You are here

function resp_img_get_best_suffix in Responsive images and styles 7

Determine best match

3 calls to resp_img_get_best_suffix()
resp_img_add_js in ./resp_img.module
Add cookie support, script and settings
resp_img_init in ./resp_img.module
Implements hook_init().
resp_img_replace_suffix in ./resp_img.module
Replace suffix if needed / possible

File

./resp_img.module, line 171

Code

function resp_img_get_best_suffix() {
  static $bestfit = FALSE;
  if ($bestfit === FALSE && isset($_COOKIE[RESP_IMG_COOKIE]) && is_numeric($_COOKIE[RESP_IMG_COOKIE])) {
    $width = $_COOKIE[RESP_IMG_COOKIE];
    $ratio = _resp_img_get_device_pixel_ratio();
    $width = $width * $ratio;
    $bestfit = variable_get('resp_img_default_suffix', '');
    $widths = resp_img_suffix_load_all_breakpoints();
    foreach ($widths as $k => $v) {
      if ($width >= $v) {
        $bestfit = $k;
        break;
      }
    }
  }
  return $bestfit;
}