如何使用原始照片的其他较小变体存储相同的图像

发布于 2025-01-30 18:54:29 字数 851 浏览 6 评论 0原文

我正在使用 jQuery fancybox插件效果很好。问题是我不喜欢在页面上加载原始图像及其大小的事实。我需要以某种方式在页面加载上加载此图片的较小变体,然后单击以显示原始图片。在花哨的盒子方面,这很容易做到。但是,较小变体的存储过程使我感到困惑。上传时,我将存储2个图像 - 原始图像和调整大小(较小的变体)。包含照片的较小变体的div设置为max宽度:500px; max-height:150px;,这就是如何调整较小的变体照片的大小。 。 500px的最大宽度150px的最大高度。另一个问题是如何保存图像的纵横比?我将如何确定是否需要存储第二张(较小)的照片。我很困惑。我在等你回复。提前致谢。

较小的变体 “

原始变体 -Fancybox打开 “

我正在使用图像干预

我的项目在 Laravel 8 上。

I'm using jQuery Fancybox Plugin which works pretty good. The problem is that I don't like the fact that on page load the original image with its size is loaded. I need to somehow load a smaller variant of this picture on page load and when clicked to show the original one. It's very easy to do when it comes to fancybox. But the storing process of the smaller variant is confusing me. On upload, I'll store 2 images - the original, and the resized (smaller variant) one. The div that is containing the smaller variant of the photo is set to max-width:500px;max-height:150px; and that's how the smaller variant photo should be resized. Max width of 500px and Max height of 150px. Another question is how will I save the aspect ratio of the image? And how will I determine whether there is a need to store a second (smaller) photo at all. I'm so confused. I'm waiting for you replies. Thanks in advance.

smaller variant
visualization1

original variant - fancybox opened
visualization2

I'm using Image Intervention.

My project is on Laravel 8.

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

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

发布评论

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

评论(1

乄_柒ぐ汐 2025-02-06 18:54:29

是的,您需要在存储空间中存储2个图像。

您需要定义图像的宽度或高度与主纵横比。查看我个人喜欢Spatie Media软件包的以下代码

// open an image file
$img = Image::make('public/foo.jpg');

// now you are able to resize the instance with maintaining aspect ratio
$img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); });


// finally we save the image as a new file
$img->save('public/foo_sm.jpg');

(在后面使用图像干预)。它使用多态关系在单独的表上处理媒体。
看看文档,令人惊讶

https://spatie.be/spatie.be/docs/laravel/laravel -Medialibrary/V10/简介

Yes, you need to store 2 images on your storage.

You need to define either width or height to main aspect ratio of the image. Check the below code

// open an image file
$img = Image::make('public/foo.jpg');

// now you are able to resize the instance with maintaining aspect ratio
$img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); });


// finally we save the image as a new file
$img->save('public/foo_sm.jpg');

I personally like spatie media package (Which uses image intervention in behind). It handles media on separate table using polymorphic relation.
Have a look into the docs, it's amazing

https://spatie.be/docs/laravel-medialibrary/v10/introduction

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