note 62244 rejected from function.imagecreatefromstring by nlopess

From: Date: Thu, 23 Feb 2006 09:40:31 +0000
Subject: note 62244 rejected from function.imagecreatefromstring by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-104286@lists.php.net to get a copy of this message
Note Submitter: junkmail at pmobl dot com ---- I run a blogging site at http://www.elmwoodstrip.org where people are posting with all kinds of phones. I know a lot of people have been having trouble using images from the Sprint PPC6700 with GD. The jpeg library always thows an error about 16 bytes of extraneous data. I decided to poke around in a hex editor and found those extraneous bytes occur right at the end of the exif data and consist of the following hex string \x00\x10\x4A\x46\x49\x46\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00 By removing this extraneous data, images can easily be manipulated by GD and the EXIF extension as a normal images. This also removes any problems using the images with GIMP which must rely on the same jpeg libraries. Here is a function that will check to see if an image is from the PPC6700 and then remove the extraneous data for you. The result can successully be used with imagecreatefromstring function checkFixPPC6700($orig){ //get the file contents $data = file_get_contents($orig); //if its a PPC 6700 image cut out the extraneous 16 bits if(strstr($data, "\x41\x70\x61\x63\x68\x65\x00\x48")){ $bad_data = "\x00\x10\x4A\x46\x49\x46\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00"; return substr_replace($data, "", strpos($data, $bad_data), strlen($bad_data)); } else { //if not from a PPC 6700 return data unaltered return $data; } }

« previous php.notes (#104286) next »