image - Is there a shorthand for all the filetypes in imagecreatefromjpeg()/png/gif/etc in PHP?
When working with PHP's imagecreatefromXXX()-methods I'm always writing annoying long constructs like this (line breaks are optimized for better readability here), where basically every line and every function used do exactly the same. Looks like a scenario that could be optimized:
switch ($mimeType) {
case 'image/jpeg': $myImage = imagecreatefromjpeg($source_image); break;
case 'image/png': $myImage = imagecreatefrompng($source_image); break;
case 'image/gif': $myImage = imagecreatefromgif($source_image); break;
// ... and so on, for every possible filetype
}
Question:
Is there a native function / shorthand in PHP that takes over this annoying long check-for-every-filetype switch ? Seems like this is a common situation but there's no easier way to do this ...
Answer
Solution:
Almost. Not from mime type, but from the stream itself:
(manual)