getImageWidth(); $new_width = 0; /* Take the info given to use by the detection and make some sense of what we need to generate. A series of checks is performed and if any fail the cached image doesn't get generated. */ switch($type) { case 'c': $new_width = $card_width; break; case 'h': $new_width = $carousel_width; break; default: $type = 'content'; $new_width = $content_width; break; } // No width means no-go if(empty($new_width)) { $generate = false; } // No reason to cache an image smaller than the requested width if($orig_width < $new_width) $generate = false; // No caching of images under 500px if($orig_width < 500) { $generate = false; } // If all rules pass we generate the image if($generate) { $cache_path = $document_root.'/image-cache'.$image_path.'/'.$new_width.'/'; $cache_file = $cache_path.$requested_file; // Check to see if we need to regenerate if (file_exists($cache_file)) { if (filemtime($cache_file) < filemtime($source_file)) { unlink($cache_file); } } // Only cache when the cached file doesn't exist if (!file_exists($cache_file)) { if (!is_dir($cache_path)) { mkdir($cache_path, 0755, true); } $image->smartResize($new_width, 0, true); $image->writeImage($cache_file); } } header("Content-Type: image/jpeg"); header("Cache-Control: private, max-age=".$browser_cache); header('Expires: '.gmdate('D, d M Y H:i:s', time()+$browser_cache).' GMT'); header('Content-Length: '.filesize($cache_file)); readfile($cache_file); ?>