【问题标题】:Intervention Image and cache Browser / Laravel 4干预图像和缓存浏览器 / Laravel 4
【发布时间】:2014-04-04 12:03:49
【问题描述】:

我正在使用Intervention Image 和他的缓存扩展Intervention Image Cache 它工作得很好。

我想要做的是在浏览器上缓存带有标题和干预的图像。

实现这一目标的最佳方法是什么?

假设我有一个路由,它将一个方法连接到我的控制器,该方法处理显示图像的响应,如下所示:

public function showImage($name_image)
    {
        // how can set the headers for get image cache on browser?
        $img = Image::cache(function($image) use ($name_image) {
               return $image->make('myFolderPathImage'."/".$name_image);
            });

        return Response::make($img, 200, array('Content-Type' => 'image/jpeg'));
    }

【问题讨论】:

标签: php caching laravel-4 image-caching


【解决方案1】:

你上面的代码对我来说效果很好,虽然这里有一些 laravel 4.2 路线的代码,它可能会有所帮助。

Route::get('/image/{image}', function($id) {
 if (!File::exists('public/img/g_icons/'.$id)) return Response::view('errors.missing', array(), 404);
 $img = Image::cache(function($image) use ($id) { $image->make('public/img/'.$id); },10080);
 return Response::make($img, 200, array('Content-Type' => 'image/png'));
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-19
    • 2018-04-20
    • 2019-03-23
    • 2015-12-07
    • 1970-01-01
    • 2017-01-28
    • 2012-10-13
    • 2014-01-25
    相关资源
    最近更新 更多