php图像保存/调整大小/显示实践

问题描述:

What are the best practices on image handling on a php driven web site when several versions of the same image are required (different sizes), bear in mind it's a high load website:

  1. Upload and automatically create all sizes needed
  2. Upload a single size image then call a single script which based on a parameters resizes/crops and displays image directly to user
  3. Upload a single then also with script generate new and cache it for further use (this would require use of file_exists() to check if generated version exists)
  4. Call image directly then if it doesn't exist redirect with htaccess to script which would generate it

当需要同一图像的多个版本时,在php驱动的网站上进行图像处理的最佳做法是什么( 不同大小),请记住它是一个高负荷的网站: p>

  1. 上传并自动创建所需的所有尺寸 li>
  2. 上传单个尺寸的图像 然后调用基于参数resize / crop的单个脚本并直接向用户显示图像 li>
  3. 上传单个,然后使用脚本生成new并将其缓存以供进一步使用(这需要使用file_exists ()检查生成的版本是否存在) li>
  4. 直接调用图像然后如果它不存在则使用htaccess重定向到将生成它的脚本 li> ol>

If its a high traffic website, i would suggest you go with #1. Also keep in mind that if this is a high traffic website, you might need to move to a CDN soon, in that case it would be ideal to generate all thumbs and upload to your CDN and load in the page with a cookie-free domain.

If your images is something like avatar or gallery image and he in many cases was be viewed by other peoples or by the people who uploading image, use option #1, this is very good way because time to generate image you can assign to upload time, then if this algorithm was be errored will be reasonable submitted to user.

But if your uploaded images can never was be viewed think about option #3, this case is not good in overall because some images may be corrupted and you know this in generation time while you must show image. I will be don't use this solution.