$send_function_name = wpws_ImageUtils::get_send_function_name($file);
if (wpws_cacheIsFunctional()) {
    // Use the cache
    $mtime = filemtime($file);
    if (wpws_ImageUtils::cached_file_is_needed($src, $width, $height, $quality, $mtime)) {
        // Cache image
        wpws_ImageUtils::remove_cached_file($src, $width, $height, $quality);
        $resized_image = wpws_ImageUtils::generate_resized_image($file, $width, $height);
        $cache_filename = wpws_ImageUtils::generate_timestamped_cache_filename($src, $width, $height, $quality, $mtime);
        $send_function_name($resized_image, WPWS_CACHE_DIR . "/" . $cache_filename, $quality);
    }
    $cached_file = wpws_ImageUtils::get_cached_file($src, $width, $height, $quality);
    header("Content-Type: " . wpws_ImageUtils::get_mime_type($file));
    header("Content-Length: " . filesize($cached_file));
    readfile($cached_file);
} else {
    // Do not use the cache
    $resized_image = wpws_ImageUtils::generate_resized_image($file, $width, $height);
    ob_start();
    $send_function_name($resized_image, "", $quality);
    header("Content-Type: " . get_mime_type($file));
    header("Content-Length: " . ob_get_length());
    ob_end_flush();
}
// Delete temporary resources
if ($resized_image) {
    imagedestroy($resized_image);
}
exit;
?>
 
 /**
  * Determines whether the cache entry needs to be updated
  * for a specified file.
  * @param string file (path)
  * @param int width to resize to
  * @param int height to resize to
  * @param int value between 0 and 100 for jpeg; null for any other format
  * @param int last modified timestamp of the file in question
  * @param boolean true if cache needs to be created / updated
  */
 function cached_file_is_needed($src, $width, $height, $quality, $timestamp)
 {
     $cached_file = wpws_ImageUtils::get_cached_file($src, $width, $height, $quality);
     if (!$cached_file) {
         return true;
     }
     $cached_file_timestamp = wpws_ImageUtils::get_mtime_from_cached_file($cached_file);
     if ($cached_file_timestamp != $timestamp) {
         return true;
     }
     return false;
 }