动态检索图像尺寸的最快方法 [英] quickest way to dynamically retrieve image dimensions

查看:128
本文介绍了动态检索图像尺寸的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

改善页面加载的一种方法是指定图像尺寸(高度宽度)。在PHP中,这可以使用getimagesize()完成,但是我可以想象如果你有很多图像,执行起来会很慢。

One way to improve page loading is to specify image dimesions (hieght width). In PHP this can be done with getimagesize(), however I can imagine this would be quite slow to execute if you have alot of images.

什么是最好的方法动态获取许多图像的图像尺寸,对页面加载的影响最小。我们正在讨论50多张图片。

What is the best way to dynamically get image dimensions of many images with minimal effect on page loading. We are talking about 50+ images.

推荐答案

我刚刚测试了55个5 + MB图像:

I've just tested with 55 pcs of 5+ MB images:

Imagemagick的getImageGeometry花费 5.3秒(因为在每个文件之后你必须重新创建imagick对象),而getimagesize通过图像在 0.032秒。后者是可以接受的。

Imagemagick's getImageGeometry took 5.3 seconds (because after each file you have to recreate the imagick object), while getimagesize went thru the images in 0.032 seconds. The latter is more than acceptable.

如果没有,请将维度存储在数据库中。

If not, store the dimensions in the database.

编辑:另外,如果你通过TCPIP获取文件,这会大大减慢这个过程。所以,如果你这样称呼:

Also, if you get the files through TCPIP, that slows down the process considerably. So, if you call it this way:

getimagesize('http://www.blabla.com/pic.jpg');

而不是

getimagesize('localdir / hereiam /pic.jpg');

你得到一些网络开销。

另外,如果这些图片始终具有EXIF数据(使用数码相机制作),那么您可以使用PHP exif_函数,例如:exif_read_data。

Plus, if those pictures consistently have EXIF data (made with a digital camera), then you can use the PHP exif_ functions, like: exif_read_data.

问题:哪个PHP版本您正在使用?较旧的4.x版本在某些文件系统上的getimagesize问题较小。

Question: which PHP version you are using? Older 4.x versions had smaller problems regarding getimagesize on certain filesystems.

这篇关于动态检索图像尺寸的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆