note 40971 deleted from function.pdf-open-image-file by nlopess

From: Date: Thu, 25 Mar 2004 14:41:52 +0000
Subject: note 40971 deleted from function.pdf-open-image-file by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-67160@lists.php.net to get a copy of this message
Note Submitter: hackajar matt yahoo trot com ---- I don't see any functions that will tell you what type of image file you will use. So why do we need one? 1.) Image files carry extensions that are not the file format from time to time. 2.) In a parsing engine, image types are not always going to be the same. It was the latter that lend me to this niffty function: function _GetImageFormat($file) { $fp = fopen($file, "r"); $data = fread($fp, filesize($file)); fclose($fp); if(substr($data, 0, 3) == "GIF") return "gif"; if(substr($data, 0, 2) == "BM") return "bitmap"; if(substr($data, 6, 4) == "JFIF") return "jpeg"; if(substr($data, 1, 3) == "PNG") return "png"; if(substr($data, 0, 2) == "II" || substr($data, 0, 2) == "MM") return "tiff"; return "UNKNOWN IMAGE TYPE!!!"; } Then you do one of these: $file = "./images/myimage.badextension"; $type = _GetImageFormat($file); if($type == "bitmap" || $type == "UNKNOWN IMAGE TYPE!!!") { die("Bad Image Format. Format: $type"); } $img = pdf_open_image_file($pdf, $type, $file);

« previous php.notes (#67160) next »