Created
July 30, 2015 16:02
-
-
Save maxkostinevich/008f7a04dfde1c68e154 to your computer and use it in GitHub Desktop.
Create Image from any friendly format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create Image from any friendly format | |
* | |
* Return: Image Resource | |
*/ | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment