Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Is image format supported by GD PHP extension?
<?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
You can’t perform that action at this time.