php imagick 获取 gif 图片的大小bug
微wx笑
2022-03-19【编程语言】
122
4
0关键字:
php imagick
今天是想找php imagick 获取图片文件的大小,结果看到这个问题。这里说明一下。
本问题涉及到的gif图片
imagick的获取图片的高度和宽度函数有问题,使用GD函数可获得正确结果 gd函数 array getimagesize ( string $filename [, array &$imageinfo ] ) getimagesize() 函数将測定不论什么 GIF,JPG,PNG,SWF。SWC。PSD。TIFF,BMP,IFF。JP2,JPX。JB2。JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型和一个能够用于普通 HTML 文件里 IMG 标记中的 height/width 文本字符串。
但是 imagick 通过 getImageWidth 和 getImageHeight 得到的结果是错误的。
通过以下代码测试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <? $imgUrl = "20140715182051892.gif" ; header( 'Content-type: text/html' ); date_default_timezone_set( "Asia/Shanghai" ); $image = new Imagick( $imgUrl ); //$image->thumbnailImage(200, 115,true); //echo $image; $size = $image ->getImagePage(); var_dump( $size ); echo "<br><br>" ; $real_width = $image ->getImageWidth(); echo $real_width ; echo "<br><br>" ; $real_height = $image ->getImageHeight(); echo $real_height ; echo "<br><br>" ; $image ->destroy(); |
没错,确实是错误的,为什么?
因为使用的方法不对。
对于 gif 图片,需要使用 $image->getImagePage(); 函数来获取大小。
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/lang/2022-03-19/1109.html