快速浏览一下 php 源代码就会发现getimagesize()
支持以下图像类型:
gif, jpeg, png, swf, psd, bmp, tiff, iff, jpc, jp2, jpx, jb2, xbm, ico
finfo_file
支持更多哑剧类型,如 duskwuff 所说。不利的一面是,它还进行了更多的检查,这使得效率稍低。
我的一个小测试:
$startTime = microtime(true);
for ($i=0; $i<50000; $i++)
getimagesize("test.png");
echo microtime(true) - $startTime;
$startTime = microtime(true);
for ($i=0; $i<50000; $i++) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$imageType = finfo_file($finfo, "test.png");
}
echo '<br>'.(microtime(true) - $startTime);
Result:
0.85886001586914
3.9046602249146