Skip to content

Commit

Permalink
Minor bugfix
Browse files Browse the repository at this point in the history
Compatibility with old-style JS snippet
  • Loading branch information
MattWilcox committed Apr 14, 2012
1 parent 8e7c8a5 commit 20741d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions adaptive-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,16 @@ function generateImage($source_file, $cache_file, $resolution) {

// does the cookie look valid? [whole number, comma, potential floating number]
if (! preg_match("/^[0-9]+[,]*[0-9\.]+$/", "$cookie_value")) { // no it doesn't look valid
setcookie("resolution", "", time() -1); // delete the mangled cookie
setcookie("resolution", "$cookie_value", time()-100); // delete the mangled cookie
}
else { // the cookie is valid, do stuff with it
$cookie_data = explode(",", $_COOKIE['resolution']);
$client_width = (int) $cookie_data[0]; // the base resolution (CSS pixels)
$pixel_density = $cookie_data[1]; // the device's pixel density factor (physical pixels per CSS pixel)
$total_width = $client_width;
$pixel_density = 1; // set a default, used for non-retina style JS snippet
if (@$cookie_data[1]) { // the device's pixel density factor (physical pixels per CSS pixel)
$pixel_density = $cookie_data[1];
}

rsort($resolutions); // make sure the supplied break-points are in reverse size order
$resolution = $resolutions[0]; // by default use the largest supported break-point
Expand Down

0 comments on commit 20741d9

Please sign in to comment.