note 85712 added to function.imagejpeg

From: Date: Sat, 13 Sep 2008 14:57:43 +0000
Subject: note 85712 added to function.imagejpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-144395@lists.php.net to get a copy of this message
I noticed through testing that my previous function would not always return the data requested... this is due to the fact that some cameras and software dont correctly write the DPI info in the JFIF header... So, my 2nd solution is to read the exif info (if available) and output the first non-zero value as the DPI... <?PHP function getJPEGresolution($filename){ if(exif_imagetype( $filename)!= IMAGETYPE_JPEG) return(false); $outRez=array(); // Read the file $exif = exif_read_data($filename, 'IFD0'); ob_start(); // start a new output buffer $image = file_get_contents($filename); // grab DPI information from the JPG header $outRez["xDPI"] = (int)(ord($image[15])>0? ord($image[15]) : $exif['XResolution'] ); $outRez["yDPI"] = (int)(ord($image[17])>0? ord($image[17]) : $exif['YResolution'] ); ob_end_clean(); // stop this output buffer //correct output if header doesn't contain dpi info:: use exif info instead $outRez["xDPI"] = ($outRez["xDPI"]>0? $outRez["xDPI"] : $exif['THUMBNAIL']['XResolution'] ); $outRez["yDPI"] = ($outRez["yDPI"]>0? $outRez["yDPI"] : $exif['THUMBNAIL']['YResolution'] ); //double check values; make sure it's just a number and not "72/1" ... if(!is_numeric($outRez["xDPI"])) $outRez["xDPI"] = (int)substr($outRez["xDPI"], 0, strpos($outRez["xDPI"],"/",1)); if(!is_numeric($outRez["yDPI"])) $outRez["yDPI"] = (int)substr($outRez["yDPI"], 0, strpos($outRez["yDPI"],"/",1)); //xDPI and yDPI should equal in value... but we output both anyway... return($outRez); }//end function getJPEGresolution ?> ---- Server IP: 61.195.146.164 Probable Submitter: 124.85.118.11 ---- Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php Edit -- https://master.php.net/note/edit/85712 Del: integrated -- https://master.php.net/note/delete/85712/integrated Del: useless -- https://master.php.net/note/delete/85712/useless Del: bad code -- https://master.php.net/note/delete/85712/bad+code Del: spam -- https://master.php.net/note/delete/85712/spam Del: non-english -- https://master.php.net/note/delete/85712/non-english Del: in docs -- https://master.php.net/note/delete/85712/in+docs Del: other reasons-- https://master.php.net/note/delete/85712 Reject -- https://master.php.net/note/reject/85712 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144395) next »