phalcon/cphalcon · error · Phalcon\Image\Exceptions\UnsupportedImageType
Installed GD does not support {mime} images
Error message
Installed GD does not support {mime} images What it means
The GD adapter handles only GIF, JPEG/JPEG2000, PNG, WEBP, WBMP and XBM - a switch on the IMAGETYPE constant returned by getimagesize(). Any other detected type (AVIF, BMP, TIFF, ICO, HEIC) falls into the default case and throws UnsupportedImageType with the detected mime, even if the GD extension itself is installed.
Source
Thrown at phalcon/Image/Adapter/Gd.zep:119
case IMAGETYPE_PNG:
let image = imagecreatefrompng(this->file);
break;
case IMAGETYPE_WEBP:
let image = imagecreatefromwebp(this->file);
break;
case IMAGETYPE_WBMP:
let image = imagecreatefromwbmp(this->file);
break;
case IMAGETYPE_XBM:
let image = imagecreatefromxbm(this->file);
break;
default:
throw new UnsupportedImageType(this->mime);
}
/** @var GdImage $image */
let this->image = image;
imagesavealpha(this->image, true);
} else {
if (null === width || null === height) {
throw new ImageLoadFailed(this->file);
}
/**
* @var positive-int $height
* @var positive-int $width
*/
let image = imagecreatetruecolor(width, height);
/** @var GdImage $image */View on GitHub (pinned to b7419de9cd)
Solutions
- Whitelist types early: $info = getimagesize($path); reject unless $info[2] is IMAGETYPE_GIF/JPEG/PNG/WEBP/WBMP/XBM
- Convert unsupported formats upstream (ImageMagick, libvips) before the GD adapter sees them
- Use Phalcon\Image\Adapter\Imagick when its delegates support the formats you accept
Example fix
// before
$image = new \Phalcon\Image\Adapter\Gd('photo.avif'); // AVIF -> throws
// after
$info = getimagesize('photo.avif');
$allowed = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_WEBP];
if (false === $info || !in_array($info[2], $allowed, true)) {
throw new \RuntimeException('Unsupported image type: ' . ($info['mime'] ?? 'unknown'));
}
$image = new \Phalcon\Image\Adapter\Gd('photo.avif'); Defensive patterns
Strategy: validation
Validate before calling
$allowed = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG, IMAGETYPE_WEBP, IMAGETYPE_WBMP, IMAGETYPE_XBM];
$info = getimagesize($path);
if (false === $info || !in_array($info[2], $allowed, true)) {
throw new \RuntimeException('Unsupported image type: ' . ($info['mime'] ?? 'unknown'));
}
$image = new \Phalcon\Image\Adapter\Gd($path); Type guard
function isGdSupportedImage(string $path): bool
{
$allowed = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG, IMAGETYPE_WEBP, IMAGETYPE_WBMP, IMAGETYPE_XBM];
$info = @getimagesize($path);
return false !== $info && in_array($info[2], $allowed, true);
} Try / catch
try { $image = new \Phalcon\Image\Adapter\Gd($path); } catch (\Phalcon\Image\Exceptions\UnsupportedImageType $e) { // convert upstream or reject
http_response_code(415);
exit('Image format not supported; please upload GIF, JPEG, PNG or WebP');
} Prevention
- Whitelist IMAGETYPE_* constants from getimagesize() instead of trusting file extensions
- Convert AVIF/BMP/TIFF/ICO to PNG or JPEG upstream (ImageMagick/libvips)
- Consider Phalcon\Image\Adapter\Imagick when you must support more formats
When it happens
Trigger: new Gd('photo.avif'); new Gd('icon.ico'); any file whose real content is BMP/TIFF regardless of its extension.
Common situations: AVIF uploads from modern clients; designers delivering TIFF/BMP assets; favicons pushed through the same image pipeline; extension-based validation passing while the actual content differs.
Related errors
- Width and height must be specified
- Width must be specified
- Height must be specified
- Failed to create image from file {file}
- The color '{color}' is not a valid hex color
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/36c9e7efbc14e132.
Report an issue: GitHub.