Made code changes to serve higher resolution images in displays with high pixel density.
This commit is contained in:
parent
80796c78f5
commit
ed5cebd3d6
@ -80,6 +80,22 @@ function photo_init(&$a) {
|
|||||||
* Other photos
|
* 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;
|
$resolution = 0;
|
||||||
|
|
||||||
if(strpos($photo,'.') !== false)
|
if(strpos($photo,'.') !== false)
|
||||||
@ -88,6 +104,23 @@ function photo_init(&$a) {
|
|||||||
if(substr($photo,-2,1) == '-') {
|
if(substr($photo,-2,1) == '-') {
|
||||||
$resolution = intval(substr($photo,-1,1));
|
$resolution = intval(substr($photo,-1,1));
|
||||||
$photo = substr($photo,0,-2);
|
$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",
|
$r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1",
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
<script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
<script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
|
<script>(function(w){var dpr=((w.devicePixelRatio===undefined)?1:w.devicePixelRatio);if(!!w.navigator.standalone){var r=new XMLHttpRequest();r.open('GET','/retinaimages.php?devicePixelRatio='+dpr,false);r.send()}else{document.cookie='devicePixelRatio='+dpr+'; path=/'}})(window)</script>
|
||||||
|
<noscript><style id="devicePixelRatio" media="only screen and (-moz-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)">html{background-image:url("/retinaimages.php?devicePixelRatio=2")}</style></noscript>
|
||||||
|
|
||||||
{{$head_css}}
|
{{$head_css}}
|
||||||
|
|
||||||
{{$js_strings}}
|
{{$js_strings}}
|
||||||
|
Reference in New Issue
Block a user