抱歉,我无法将此作为评论添加到先前的答案,但我没有代表。做一些快速而肮脏的测试,我还发现 exec("identify -ping... 比没有 -ping 快 20 倍。但 getimagesize() 似乎仍然快 200 倍。
所以我会说 getimagesize() 是更快的方法。我只在 jpg 上测试过,而不是在 png 上测试过。
测试只是
$files = array('2819547919_db7466149b_o_d.jpg', 'GP1-green2.jpg', 'aegeri-lake-switzerland.JPG');
foreach($files as $file){
$size2 = array();
$size3 = array();
$time1 = microtime();
$size = getimagesize($file);
$time1 = microtime() - $time1;
print "$time1 \n";
$time2 = microtime();
exec("identify -ping $file", $size2);
$time2 = microtime() - $time2;
print $time2/$time1 . "\n";
$time2 = microtime();
exec("identify $file", $size3);
$time2 = microtime() - $time2;
print $time2/$time1 . "\n";
print_r($size);
print_r($size2);
print_r($size3);
}