From ed5cebd3d6b87a5c2254f3fa48b03d93558fa7bc Mon Sep 17 00:00:00 2001 From: root Date: Sat, 10 May 2014 11:15:27 -0700 Subject: Made code changes to serve higher resolution images in displays with high pixel density. --- mod/photo.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/photo.php b/mod/photo.php index 1319f9569..b351ce17f 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -80,6 +80,22 @@ function photo_init(&$a) { * Other photos */ + /* Check for a cookie to indicate display pixel density, in order to detect high-resolution + displays. This procedure was derived from the "Retina Images" by Jeremey Worboys, + used in accordance with the Creative Commons Attribution 3.0 Unported License. + Project link: https://github.com/Retina-Images/Retina-Images + License link: http://creativecommons.org/licenses/by/3.0/ + */ + $cookie_value = false; + if (isset($_COOKIE['devicePixelRatio'])) { + $cookie_value = intval($_COOKIE['devicePixelRatio']); + } + else { + // Force revalidation of cache on next request + $cache_directive = 'no-cache'; + $status = 'no cookie'; + } + $resolution = 0; if(strpos($photo,'.') !== false) @@ -88,7 +104,24 @@ function photo_init(&$a) { if(substr($photo,-2,1) == '-') { $resolution = intval(substr($photo,-1,1)); $photo = substr($photo,0,-2); + // Serve high-resolution images regardless (this is rude): + // [Note: this can be improved by setting a cookie to indicate that the user is viewing on a high-resolution display] + if ($resolution == 2 && ($cookie_value > 1)) + { + $resolution = 1; + } } + + // If using resolution 1, make sure it exists before proceeding: + if ($resolution == 1) + { + $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", + dbesc($photo), + intval($resolution) + ); + if (!($r)) + $resolution = 2; + } $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", dbesc($photo), @@ -125,7 +158,7 @@ function photo_init(&$a) { dbesc($photo), intval($resolution) ); - + if($r) { logger('mod_photo: forbidden. ' . $a->query_string); $observer = $a->get_observer(); -- cgit v1.2.3 From 874b8d40ff14e39bac4875efbaee2f24121d20bd Mon Sep 17 00:00:00 2001 From: root Date: Sat, 10 May 2014 11:22:00 -0700 Subject: Changed some comments. --- mod/photo.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mod') diff --git a/mod/photo.php b/mod/photo.php index b351ce17f..9302278b6 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -104,8 +104,7 @@ function photo_init(&$a) { if(substr($photo,-2,1) == '-') { $resolution = intval(substr($photo,-1,1)); $photo = substr($photo,0,-2); - // Serve high-resolution images regardless (this is rude): - // [Note: this can be improved by setting a cookie to indicate that the user is viewing on a high-resolution display] + // If viewing on a high-res screen, attempt to serve a higher resolution image: if ($resolution == 2 && ($cookie_value > 1)) { $resolution = 1; -- cgit v1.2.3