Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created July 30, 2015 16:02
Show Gist options
  • Save maxkostinevich/008f7a04dfde1c68e154 to your computer and use it in GitHub Desktop.
Save maxkostinevich/008f7a04dfde1c68e154 to your computer and use it in GitHub Desktop.
Create Image from any friendly format
/**
* 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