简体   繁体   English

PHP,操纵图像和缩略图?

[英]PHP, manipulating images and thumbnails?

I am using php and mysql. 我正在使用php和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. 我允许我的注册用户上传照片,这些照片以文件系统格式存储,然后我将保留原始/最大尺寸:宽度:1600px和高度: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. 在用户个人资料页面上,我想显示图像,它可能是5种缩略图的一种:500x500、300x300、200x200、100x100或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 我正在考虑创建1个缩略图,然后从该缩略图中调整[img src =“” width =“ XX”]标签的大小,或者将其他缩略图的大小存储在数据库中,然后获取并显示它

  2. Create 5 thumbnails for each photos? 为每张照片创建5张缩略图? (I am afraid this is a bad way) (恐怕这是一个坏方法)

Whats the best practices? 什么是最佳做法?

Don't use the width HTML attribute to resize, because that will waste both your and the client's bandwidth. 不要使用width HTML属性来调整大小,因为这会浪费您和客户端的带宽。 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. 可能的折衷办法是将它们存储在memcached中。 Also, don't forget about HTTP caching. 另外,不要忘记HTTP缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM