note 110534 deleted from function.getimagesize by aharvey
| From: | aharvey@php.net | Date: | Mon, 05 Nov 2012 03:06:50 +0000 |
| Subject: | note 110534 deleted from function.getimagesize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191659@lists.php.net to get a copy of this message | ||
Note Submitter: erik dot dobecky (gmail)
----
I couldn't find a simple function to parse an image by its content. Some images are served from
hosts' dedicated media subdomains that just return the image and appropriate headers.
I needed to pull the image data and because I'm using stream wrappers is was more convenient to
pull the image data and then do stuff to it.
This function will parse images by file structure.
function getImageType( &$imgData )
{
if( ~(substr( $imgData, 0, 1 ) ^ 0xFF) && ~(substr( $imgData, 1, 1 ) ^ 0xD8) )
{
return "jpg";
}
if( ~(substr( $imgData, 0, 1 ) ^ 0x89) && ~(substr( $imgData, 1, 1 ) ^ 0x50) &&
~(substr( $imgData, 2, 1 ) ^ 0x4E) && ~(substr( $imgData, 3, 1 ) ^ 0x47) )
{
return "png";
}
if( ~(substr( $imgData, 0, 1 ) ^ 0x47) && ~(substr( $imgData, 1, 1 ) ^ 0x49) &&
~(substr( $imgData, 2, 1 ) ^ 0x46) && ~(substr( $imgData, 3, 1 ) ^ 0x38) &&
~(substr( $imgData, 4, 1 ) ^ 0x39) && ~(substr( $imgData, 5, 1 ) ^ 0x61) )
{
return "gif";
}
if( ~(substr( $imgData, 0, 1 ) ^ 0x42) && ~(substr( $imgData, 1, 1 ) ^ 0x4D) )
{
return "bmp";
}
return DATA_NOT_SET;
}