在图像干预中使用缓存和克隆而不只使用克隆好吗?

发布于 2025-02-04 22:25:46 字数 405 浏览 2 评论 0原文

我想制作不同尺寸的图像。缓存文件并克隆它以生成不同的尺寸,这很好吗?或者,如果我只使用克隆(没有缓存),没有什么不同?

没有缓存:

$image->make($this->file);

使用缓存:

$image = Image::cache(function($image) {
    $image->make($this->file);
});

生成不同的尺寸:

for($sizes as $size) {
    $clonedImage = clone $image;
    // Generate different sizes of that image...
}

I want to make different sizes of an image. Is it good to cache the file and clone it for generating different sizes? Or no different if I use only clone (without cache)?

Without cache:

$image->make($this->file);

With cache:

$image = Image::cache(function($image) {
    $image->make($this->file);
});

Generate different sizes:

for($sizes as $size) {
    $clonedImage = clone $image;
    // Generate different sizes of that image...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失与倦" 2025-02-11 22:25:46

生成不同的尺寸与缓存图像无关。

Image :: CACHE将使用您的Laravel项目的默认缓存驱动程序。当您想使用Image :: Cache检索图像时,它将检查是否在缓存(hit)中可用(hist)(遗漏)。当可用的情况下,操作将很快,并且如果不是,则需要一些时间,具体取决于负责构建要缓存数据的业务逻辑。

您将需要在 中在中生成的每个大小。我还建议使用 Glide ,它只会使您的生活更轻松,因为它可以自动处理缓存,您可以使您的生活更加轻松通过HTTP操纵图像。

Generating different sizes has nothing to do with caching the image.

Image::cache will use your the default cache driver of your Laravel project. When you want to retrieve an image using Image::cache, it will check if it's available in the cache (hit) or not (miss). When it's available, the operation will be fast and when it's not, it will take some time depending on the business logic that is responsible of building the data to be cached.

You will need to cache every single size you generate in the for loop you wrote. I would also suggest using glide, it will just make your life easier as it handles cache automatically and you can manipulate images on-the-go over HTTP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文