note 110547 modified in function.imagecreatefromjpeg by danbrown

From: Date: Thu, 06 Dec 2012 14:23:17 +0000
Subject: note 110547 modified in function.imagecreatefromjpeg by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192332@lists.php.net to get a copy of this message
This little function allows you to create an image based on the popular image types without worrying about what it is: <?php function imageCreateFromAny($filepath) { $type = exif_imagetype($filepath); // [] if you don't have exif you could use getImageSize() $allowedTypes = array( 1, // [] gif 2, // [] jpg 3, // [] png 6 // [] bmp ); if (!in_array($type, $allowedTypes)) { return false; } switch ($type) { case 1 : $im = imageCreateFromGif($filepath); break; case 2 : $im = imageCreateFromJpeg($filepath); break; case 3 : $im = imageCreateFromPng($filepath); break; case 6 : $im = imageCreateFromBmp($filepath); break; } return $im; } ?> --was-- This little function allows you to create an image based on the popular image types without worrying about what it is: function imageCreateFromAny($filepath) { $type = exif_imagetype($filepath); // [] if you don't have exif you could use getImageSize() $allowedTypes = array( 1, // [] gif 2, // [] jpg 3, // [] png 6 // [] bmp ); if (!in_array($type, $allowedTypes)) { return false; } switch ($type) { case 1 : $im = imageCreateFromGif($filepath); break; case 2 : $im = imageCreateFromJpeg($filepath); break; case 3 : $im = imageCreateFromPng($filepath); break; case 6 : $im = imageCreateFromBmp($filepath); break; } return $im; } http://php.net/manual/en/function.imagecreatefromjpeg.php

« previous php.notes (#192332) next »