PHP,操作图像和缩略图?
我正在使用 php 和 mysql。我允许我的注册用户上传照片,照片以文件系统格式存储,然后我将保留原始/最大尺寸:宽度:1600px 和高度:1200px。在用户个人资料页面中,我想显示图像,它可能是 5 种缩略图之一:500x500、300x300、200x200、100x100 或 50x50。创建缩略图的最佳方法是什么,这是我当前的解决方案:
我正在考虑创建 1 个缩略图,然后从该缩略图开始,我将在 [img src="" width="XX"] 标签中调整大小,或者,将不同的缩略图大小存储在数据库中,然后获取并显示它
为每张照片创建 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:
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
Create 5 thumbnails for each photos? (I am afraid this is a bad way)
Whats the best practices?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用 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.