Skip to content

Instantly share code, notes, and snippets.

@szepeviktor
Created October 22, 2019 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szepeviktor/7fa9e18f8d58c652104fd77c6b9e618b to your computer and use it in GitHub Desktop.
Save szepeviktor/7fa9e18f8d58c652104fd77c6b9e618b to your computer and use it in GitHub Desktop.
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