{"record":{"id":"36c9e7efbc14e132","repo":"phalcon/cphalcon","slug":"installed-gd-does-not-support-mime-images","errorCode":null,"errorMessage":"Installed GD does not support {mime} images","messagePattern":"Installed GD does not support (.+?) images","errorType":"exception","errorClass":"Phalcon\\Image\\Exceptions\\UnsupportedImageType","httpStatus":null,"severity":"error","filePath":"phalcon/Image/Adapter/Gd.zep","lineNumber":119,"sourceCode":"\n                case IMAGETYPE_PNG:\n                    let image = imagecreatefrompng(this->file);\n                    break;\n\n                case IMAGETYPE_WEBP:\n                    let image = imagecreatefromwebp(this->file);\n                    break;\n\n                case IMAGETYPE_WBMP:\n                    let image = imagecreatefromwbmp(this->file);\n                    break;\n\n                case IMAGETYPE_XBM:\n                    let image = imagecreatefromxbm(this->file);\n                    break;\n\n                default:\n                    throw new UnsupportedImageType(this->mime);\n            }\n\n            /** @var GdImage $image */\n            let this->image = image;\n\n            imagesavealpha(this->image, true);\n        } else {\n            if (null === width || null === height) {\n                throw new ImageLoadFailed(this->file);\n            }\n\n            /**\n             * @var positive-int $height\n             * @var positive-int $width\n             */\n            let image = imagecreatetruecolor(width, height);\n\n            /** @var GdImage $image */","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Image/Adapter/Gd.zep#L101-L137","documentation":"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.","triggerScenarios":"new Gd('photo.avif'); new Gd('icon.ico'); any file whose real content is BMP/TIFF regardless of its extension.","commonSituations":"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.","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"],"exampleFix":"// before\n$image = new \\Phalcon\\Image\\Adapter\\Gd('photo.avif'); // AVIF -> throws\n\n// after\n$info = getimagesize('photo.avif');\n$allowed = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_WEBP];\nif (false === $info || !in_array($info[2], $allowed, true)) {\n    throw new \\RuntimeException('Unsupported image type: ' . ($info['mime'] ?? 'unknown'));\n}\n$image = new \\Phalcon\\Image\\Adapter\\Gd('photo.avif');","handlingStrategy":"validation","validationCode":"$allowed = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG, IMAGETYPE_WEBP, IMAGETYPE_WBMP, IMAGETYPE_XBM];\n$info = getimagesize($path);\nif (false === $info || !in_array($info[2], $allowed, true)) {\n    throw new \\RuntimeException('Unsupported image type: ' . ($info['mime'] ?? 'unknown'));\n}\n$image = new \\Phalcon\\Image\\Adapter\\Gd($path);","typeGuard":"function isGdSupportedImage(string $path): bool\n{\n    $allowed = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG, IMAGETYPE_WEBP, IMAGETYPE_WBMP, IMAGETYPE_XBM];\n    $info = @getimagesize($path);\n    return false !== $info && in_array($info[2], $allowed, true);\n}","tryCatchPattern":"try { $image = new \\Phalcon\\Image\\Adapter\\Gd($path); } catch (\\Phalcon\\Image\\Exceptions\\UnsupportedImageType $e) { // convert upstream or reject\n    http_response_code(415);\n    exit('Image format not supported; please upload GIF, JPEG, PNG or WebP');\n}","preventionTips":["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"],"tags":["php","phalcon","image","gd","file-format"],"backgroundTag":"unsupported-image-format","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}