You are here

function adaptive_image_resolution in Adaptive Image 7

Determine current resolution

3 calls to adaptive_image_resolution()
adaptive_image_preprocess_image in ./adaptive_image.module
Implements template_preprocess_image().
adaptive_image_scale_form in ./adaptive_image.module
Form structure for the image scale form.
adaptive_image_style_deliver in ./adaptive_image.image.inc
Copy of image_style_deliver() for use with adaptive images.

File

./adaptive_image.module, line 238
Adaptive Image - Adaptive images for Drupal

Code

function adaptive_image_resolution($resolutions) {
  $resolution = '';

  /* Check to see if a valid cookie exists */
  if (count($resolutions) && isset($_COOKIE['adaptive_image'])) {
    if (is_numeric($_COOKIE['adaptive_image'])) {
      $client_width = (int) $_COOKIE['adaptive_image'];

      // store the cookie value in a variable

      /* the client width in the cookie is valid, now fit that number into the correct resolution break point */
      rsort($resolutions);

      // make sure the supplied break-points are in reverse size order
      $resolution = $resolutions[0];

      // by default it's the largest supported break-point
      foreach ($resolutions as $break_point) {

        // filter down
        if ($client_width <= trim($break_point, ' ')) {
          $resolution = $break_point;
        }
      }
    }
    else {
      setcookie("adaptive_image", "", time() - 1);

      // delete the mangled cookie
    }
  }
  return $resolution;
}