note 19876 deleted from function.getimagesize by derick
| From: | derick@php.net | Date: | Tue, 18 Oct 2005 11:33:41 +0000 |
| Subject: | note 19876 deleted from function.getimagesize by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97159@lists.php.net to get a copy of this message | ||
Note Submitter: tightcode_nosp@m_hotmail
----
If you are using a php version with the bug where GetImageSize returns nothing on certain types of
jpeg images, the following replacement should solve the problem until you have upgraded.
It accuratly duplicates the 1st and 2nd array element which are the ones I personally needed. I
however added the 4th array element and a crude implementation of the 3rd since some people may need
the functionality or find it usefull.
I hopefully reformated the function to not be wordwrapped and it is worth noting that as it is
written, it only will work on local files. Additional error checking may be wise.
function sgetimagesize($filename) {
$ftype_array = array(".gif"=>"1",
".jpg"=>"2",
".jpeg"=>"2",
".png"=>"3",
".swf"=>"4",
".psd"=>"5",
".bmp"=>"6");
if (is_file($filename)) {
$fd = @fopen($filename,"r");
$image_string = fread($fd,filesize($filename));
$im = ImageCreateFromString($image_string);
$ftype = $ftype_array[get_file_ext($filename)];
$gis[0] = ImageSX($im);
$gis[1] = ImageSY($im);
$gis[2] = ($ftype?$ftype:"0");
$gis[3] = "width={$gis[0]} height={$gis[1]}";
ImageDestroy($im);
return $gis_array;
}
else { return false; }
}
Cheers,
Tightcode