/** * Create a response that will force a image to be displayed inline. * * @param string $path Path to the image * @param string $name Filename * @param int $lifetime Lifetime in browsers cache * @return Response */ public static function inline($path, $name = null, $lifetime = 0) { if (is_null($name)) { $name = basename($path); } $filetime = filemtime($path); $etag = md5($filetime . $path); $time = gmdate('r', $filetime); $expires = gmdate('r', $filetime + $lifetime); $length = filesize($path); $headers = array('Content-Disposition' => 'inline; filename="' . $name . '"', 'Last-Modified' => $time, 'Cache-Control' => 'must-revalidate', 'Expires' => $expires, 'Pragma' => 'public', 'Etag' => $etag); // If enabled, we need to disable the profiler LaravelConfig::set('application.profiler', false); // Check the Browsers cache $headerTest1 = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $time; $headerTest2 = isset($_SERVER['HTTP_IF_NONE_MATCH']) && str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == $etag; if ($headerTest1 || $headerTest2) { //image is cached by the browser, we dont need to send it again return static::make('', 304, $headers); } $fileinfos = Imwg::imageInfo($path); $headers = array_merge($headers, array('Content-Type' => $fileinfos['mime'], 'Content-Length' => $length)); return static::make(File::get($path), 200, $headers); }
$cache_filename = Filecache::retrieveValidFilename($image, $options); if (Filecache::has($cache_filename, $lifetime)) { // The cache has our file, get the full filepath $cached_image = Filecache::getPath($cache_filename); return Resp::inline($cached_image, basename($image), $lifetime); } else { // File is not cached, lets get a path $cache_image_path = Filecache::getPath($cache_filename); $imwg = Imwg::open($image); parseOptions($imwg, $opt); $imwg->save($cache_image_path); return Resp::inline($cache_image_path, basename($image), $lifetime); } } else { // caching is disabled $imwg = Imwg::open($image); parseOptions($imwg, $opt); return $imwg->display(); #$imwg->display(); #exit(); } } // No config file // Check if the image exists if (File::exists($image)) { return Resp::inline($image); } // No config and // no image found return Response::error('404'); });