Created
October 22, 2019 15:18
-
-
Save szepeviktor/7fa9e18f8d58c652104fd77c6b9e618b to your computer and use it in GitHub Desktop.
Is image format supported by GD PHP extension?
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 | |
/** | |
* Is image format supported?? | |
* | |
* @see https://www.php.net/manual/en/function.exif-imagetype.php | |
* @see https://www.php.net/manual/en/function.gd-info.php | |
* | |
* @param string File path. | |
* @return bool | |
*/ | |
function is_image_format_supported($file) | |
{ | |
$imagetype2gdinfo = [ | |
IMAGETYPE_GIF => 'GIF Read Support', | |
IMAGETYPE_JPEG => 'JPEG Support', | |
IMAGETYPE_PNG => 'PNG Support', | |
IMAGETYPE_WBMP => 'WBMP Support', | |
IMAGETYPE_XBM => 'XBM Support', | |
IMAGETYPE_WEBP => 'WebP Support', | |
// IMAGETYPE_BMP => '???', | |
]; | |
$fileType = exif_imagetype($file); | |
$currentGdInfo = gd_info(); | |
return isset($imagetype2gdinfo[$fileType]) && $currentGdInfo[$imagetype2gdinfo[$fileType]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment