简体   繁体   English

读取图像尺寸:exif,gd和imagemagick?

[英]Read image dimensions: exif vs gd vs imagemagick?

Processing already done by imagick. imagick已经完成处理。

But we have a bunch of files already processed and in one of method want to extract only their width/height. 但是我们已经处理了一堆文件,在一种方法中,我们只想提取其宽度/高度。

As I understand, Imagick to getImageWidth reads whole file and also loads it inside it's internal structures. 据我了解,Imagick的getImageWidth读取整个文件,并将其加载到其内部结构中。

I want to know -- is exif or gd has some more lightweight methods to get only widht/height of image. 我想知道-exif或gd有一些更轻量的方法来仅获取图像的高度/高度。

// It's ok to trust to exif meta //信任exif meta是可以的

I just did a benchmark on 127 PNG images . 我只是对127个PNG图像进行了基准测试。 It seems GD is the fastest among GD and Imagick. 似乎GD是 GD和Imagick中最快的。 If you only want to use ImageMagick then load the file with pingImage first and retrieve width and height. 如果只想使用ImageMagick,则首先使用pingImage加载文件并获取宽度和高度。 This is the fastest in IM methods. 这是IM方法中最快的。 But still 3 times slower than GD. 但是仍然比GD慢3倍。

+------------------------------------+---------------------------+
| Script/Task name                   | Execution time in seconds |
+------------------------------------+---------------------------+
| GD                                 | 0.010726928710938         |
| IM Multiple Instance               | 1.9311830997467           |
| IM Single Instance                 | 2.0554959774017           |
| IM Single Instance identifyImage   | 1.4270191192627           |
| IM Single Instance pingImage       | 0.036259889602661         |
| imagedimension-exif-gd-imagick.php | 5.467                     |
+------------------------------------+---------------------------+

ImageMagic Multiple Instance means initializing different instance for different image ImageMagic Multiple Instance意味着为不同的图像初始化不同的实例

foreach($pngs as $png){
    $im = new Imagick($png);
    list($width, $height) =array($im->getimagewidth(), $im->getimageheight());
}

ImageMagic Single Instance means using a single iterate-able instance of Imagick ImageMagic单个实例意味着使用Imagick的单个可迭代实例

$images =  new \Imagick($pngs);
foreach($images as $im){
    list($width, $height) =array($im->getimagewidth(), $im->getimageheight());
}

ImageMagick Single Instance pingImage means getting dimension after loading it using pingImage ImageMagick单实例pingImage表示使用pingImage加载后获取尺寸

$im = new Imagick();
foreach($pngs as $png){
    $im->pingImage($png);
    list($width, $height) =array($im->getimagewidth(), $im->getimageheight());
}

ImageMagick Single Instance identifyImage means identifying image after loading it with pingImage(); ImageMagick单实例的identifyImage意味着在使用pingImage();加载后识别图像pingImage();

$im = new Imagick();
foreach($pngs as $png){
    $im->pingImage($png);
    $im_info = $im->identifyImage();
    extract($im_info['geometry']);
    //echo $width. "x$height\n";
}

And finaly the GD, 最后是GD,

foreach($pngs as $png) {
    list($width, $height) = getimagesize ($png);
}

Note: Exif extension can not get image dimension . 注意: Exif扩展名无法获取图像尺寸 This is written in PHP manual, 这是用PHP手册编写的,

Height and Width are computed the same way getimagesize() does so their values must not be part of any header returned. 高度宽度的计算方法与getimagesize()相同,因此它们的值一定不能成为返回的任何标头的一部分。 Also, html is a height/width text string to be used inside normal HTML. 此外, html是在常规HTML中使用的高度/宽度文本字符串。

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

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