note 19876 added to function.getimagesize

From: Date: Thu, 14 Mar 2002 00:16:12 +0000
Subject: note 19876 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-27762@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/function.getimagesize.php http://master.php.net/manage/user-notes.php?action=edit+19876 http://master.php.net/manage/user-notes.php?action=delete+19876 http://master.php.net/manage/user-notes.php?action=reject+19876

« previous php.notes (#27762) next »