Last active
July 11, 2019 23:23
-
-
Save adamcrampton/38c6c496bbcb0887955d6d0917ebecbb to your computer and use it in GitHub Desktop.
Returns image Mime type
This file contains 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
<?php | |
/** | |
* @param string $imageUrl | |
* @return string|bool | |
*/ | |
public function getImageMimeType($imageUrl) { | |
$mimeTypes = [ | |
IMAGETYPE_GIF => "image/gif", | |
IMAGETYPE_JPEG => "image/jpg", | |
IMAGETYPE_PNG => "image/png", | |
IMAGETYPE_ICO => "image/ico", | |
IMAGETYPE_SWF => "image/swf", | |
IMAGETYPE_PSD => "image/psd", | |
IMAGETYPE_BMP => "image/bmp", | |
IMAGETYPE_TIFF_II => "image/tiff", | |
IMAGETYPE_TIFF_MM => "image/tiff", | |
IMAGETYPE_JPC => "image/jpc", | |
IMAGETYPE_JP2 => "image/jp2", | |
IMAGETYPE_JPX => "image/jpx", | |
IMAGETYPE_JB2 => "image/jb2", | |
IMAGETYPE_SWC => "image/swc", | |
IMAGETYPE_IFF => "image/iff", | |
IMAGETYPE_WBMP => "image/wbmp", | |
IMAGETYPE_XBM => "image/xbm" | |
]; | |
if (($imageType = exif_imagetype($imageUrl)) && (array_key_exists($imageType, $mimeTypes))) { | |
return $mimeTypes[$imageType]; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment