note 91163 deleted from function.getimagesize by thiago
| From: | thiago@php.net | Date: | Thu, 28 May 2009 12:03:54 +0000 |
| Subject: | note 91163 deleted from function.getimagesize by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156104@lists.php.net to get a copy of this message | ||
Note Submitter: $user="zaxarb"; $host="gmail.com";
----
<?
function getsizeandformat($file){
if(!$fp=@fopen($file,"rb")) return false;
$first=unpack("H*first",fread($fp,4));
extract($first);
if($first=="89504e47") $format="PNG";
elseif(strpos($first,"474946")===0) $format="GIF";
elseif(strpos($first,"ffd8")===0) $format="JPEG";
else {fclose($fp); return false;}
if($format=="GIF"):
fseek($fp,6);
$size=unpack("vwidth/vheight",fread($fp,4));
$size["format"]="GIF";
endif;
if($format=="JPEG"):
fseek($fp,0);
$bytes=null;
while(!feof($fp)):
$bytes.=fread($fp,50);
$hex=unpack("H*hex",$bytes);
extract($hex);
if(($pos=strpos($hex,"ffc0"))!==false):
$bytes.=fread($fp,20);
$hex=unpack("H*hex",$bytes);
extract($hex);
break;
endif;
endwhile;
$hex=substr($hex,$pos+10,8);
list($height,$width)=str_split($hex,4);
$size=array("width"=>hexdec($width), "height"=>hexdec($height),
"format"=>"JPEG");
endif;
if($format=="PNG"):
fseek($fp,0);
$bytes=null;
while(!feof($fp)):
$bytes.=fread($fp,50);
$hex=unpack("H*hex",$bytes);
extract($hex);
if(($pos=strpos($hex,"49484452"))!==false):
$bytes.=fread($fp,20);
$hex=unpack("H*hex",$bytes);
extract($hex);
break;
endif;
endwhile;
$hex=substr($hex,$pos+8,16);
list($width,$height)=str_split($hex,8);
$size=array("width"=>hexdec($width), "height"=>hexdec($height),
"format"=>"PNG");
endif;
fclose($fp);
return $size;}
?>