note 110534 added to function.getimagesize

From: Date: Fri, 02 Nov 2012 17:50:13 +0000
Subject: note 110534 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-191643@lists.php.net to get a copy of this message
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; } ---- Server IP: 192.41.42.26 Probable Submitter: 173.66.129.132 ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- https://master.php.net/note/edit/110534 Del: integrated -- https://master.php.net/note/delete/110534/integrated Del: useless -- https://master.php.net/note/delete/110534/useless Del: bad code -- https://master.php.net/note/delete/110534/bad+code Del: spam -- https://master.php.net/note/delete/110534/spam Del: non-english -- https://master.php.net/note/delete/110534/non-english Del: in docs -- https://master.php.net/note/delete/110534/in+docs Del: other reasons-- https://master.php.net/note/delete/110534 Reject -- https://master.php.net/note/reject/110534 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191643) next »