gpt4 book ai didi

php - 使用 Intervention/ImageCache 和 Laravel 清除所有图像操作的缓存

转载 作者:行者123 更新时间:2023-12-02 04:26:53 38 4
gpt4 key购买 nike

我正在尝试找出一种方法来清除使用 Intervention/ImageCache 的操作模板创建的图像的所有操作的缓存(将来可能还会使用缓存功能)。

我有一些在图像上运行自定义过滤器的操作模板:

'thumbnail' => function($image) {
return $image->filter(new ImageFilters\Fit(150));
},

过滤器从数据库中获取焦点,然后根据需要使用焦点来运行适当的函数。

public function applyFilter(Image $image)
{
$fp = Media::where('file_name', $image->filename)->pluck('focal_point');
$fp = $fp ?: 'center';
return $image->fit($this->width, $this->height, function(){return true;}, $fp);
}

这一切都工作正常,但是当用户更改焦点时,由于缓存,图像不会更新。我需要一种方法来全面清除该特定图像的缓存。

据我所知,每个被操作的图像都被赋予了由 md5 哈希组成的自己唯一的缓存 key ,但我找不到任何方法来定位单个图像的所有操作。

最佳答案

即使问题已经过去了,我也想提出一个解决方案:

// get an instance of the ImageCache class
$imageCache = new \Intervention\Image\ImageCache();

// get a cached image from it and apply all of your templates / methods
$image = $imageCache->make($pathToImage)->filter(new TemplateClass);

// remove the image from the cache by using its internal checksum
Cache::forget($image->checksum());

每当您对图像进行更改并影响所应用的滤镜(例如焦点)时,请执行此行。当请求缓存的图像时,将使用新值再次创建该图像。

希望这有帮助,理查德

关于php - 使用 Intervention/ImageCache 和 Laravel 清除所有图像操作的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26335527/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com