简体   繁体   English

PHP图像保存/调整大小/显示做法

[英]php image save/resize/show practices

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: 需要相同图像的多个版本(不同大小)时,在php驱动的网站上进行图像处理的最佳实践是什么,请记住这是一个高负载的网站:

  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) 上载单个文件,然后还使用脚本生成新文件并将其缓存以备将来使用(这需要使用file_exists()来检查是否存在生成的版本)
  4. Call image directly then if it doesn't exist redirect with htaccess to script which would generate it 直接调用图像,如果它不存在,则使用htaccess重定向到将生成图像的脚本

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. 还要记住,如果这是一个高流量的网站,则可能需要尽快移至CDN,在这种情况下,最好生成所有大拇指并上传到CDN并使用无Cookie的域加载到页面中。

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. 如果您的图像是头像或画廊图像之类的东西,并且在很多情况下他是被其他人或上载图像的人查看的,请使用选项#1 ,这是一种很好的方法,因为生成图像的时间可以分配给上载时间,则如果此算法有误,则会合理地提交给用户。

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. 但是,如果无法查看您上传的图像,请考虑选项#3 ,这种情况总体上不好,因为某些图像可能已损坏,并且您必须在生成时知道这一点,因此必须显示图像。 I will be don't use this solution. 我将不会使用此解决方案。

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

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