<?php $img ='123.jpg'; //以檔案方式開啟 $size_info1 = getimagesize($img); //以字串格式開啟 $data = file_get_contents($img); $size_info2 = getimagesizefromstring($data); echo "<pre>"; print_r($size_info1); print_r($size_info2); ?>執行以上程式的結果如下:
Array
(
[0] => 961
[1] => 640
[2] => 2
[3] => width="961" height="640"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
Array
(
[0] => 961
[1] => 640
[2] => 2
[3] => width="961" height="640"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)