PHP,操作图像和缩略图?

发布于 2024-09-03 05:22:20 字数 365 浏览 3 评论 0原文

我正在使用 php 和 mysql。我允许我的注册用户上传照片,照片以文件系统格式存储,然后我将保留原始/最大尺寸:宽度:1600px 和高度:1200px。在用户个人资料页面中,我想显示图像,它可能是 5 种缩略图之一:500x500、300x300、200x200、100x100 或 50x50。创建缩略图的最佳方法是什么,这是我当前的解决方案:

  1. 我正在考虑创建 1 个缩略图,然后从该缩略图开始,我将在 [img src="" width="XX"] 标签中调整大小,或者,将不同的缩略图大小存储在数据库中,然后获取并显示它

  2. 为每张照片创建 5 个缩略图? (恐怕这是一个不好的方法)

什么是最佳实践?

I am using php and mysql. I allow my registered users to upload photos, the photos are store in filesystem format, then I will keep the original/max size of : width: 1600px and heigh: 1200px. In the user profile page, I would like to display the image, it maybe one of the 5 types of thumnails: 500x500, 300x300, 200x200, 100x100 or 50x50. What is the best way to create the thumbnails, here are my current solutions:

  1. I am thinking of create 1 thumbnail, then from that thumbnail, i will resize in [img src="" width="XX"] tag, alternatively, store the different thumbnails size in database, then get and display it

  2. Create 5 thumbnails for each photos? (I am afraid this is a bad way)

Whats the best practices?

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

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

发布评论

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

评论(1

任谁 2024-09-10 05:22:20

不要使用 width HTML 属性来调整大小,因为这会浪费您和客户端的带宽。您需要以所需的确切尺寸提供您使用的所有图像。缩略图的存储位置以及是否存储取决于使用模式。一个可能的折衷方案是将它们存储在内存缓存中。另外,不要忘记 HTTP 缓存。

Don't use the width HTML attribute to resize, because that will waste both your and the client's bandwidth. You need to should serve all the images you use with the exact size desired. Where and whether you store the thumbnails depends on the on the usage pattern. A possible compromise would be to store them in memcached. Also, don't forget about HTTP caching.

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