{"record":{"id":"1b132518688adc0d","repo":"Intervention/image","slug":"failed-to-retrieve-image-format","errorCode":null,"errorMessage":"Failed to retrieve image format","messagePattern":"Failed to retrieve image format","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/FilePathImageDecoder.php","lineNumber":63,"sourceCode":"     */\n    public function decode(mixed $input): ImageInterface\n    {\n        // make sure path is valid\n        $path = self::readableFilePathOrFail($input);\n\n        try {\n            $imagick = new Imagick();\n            $imagick->readImage($path);\n        } catch (ImagickException) {\n            throw new ImageDecoderException(\n                'Failed to decode image data from file \"' . $path . '\"',\n            );\n        }\n\n        try {\n            $originalFormat = $imagick->getImageFormat();\n        } catch (ImagickException $e) {\n            throw new ImageDecoderException('Failed to retrieve image format', previous: $e);\n        }\n\n        // decode image\n        $image = parent::decode($imagick);\n\n        // set file path on origin\n        $image->origin()->setFilePath($path);\n\n        // extract exif data for the appropriate formats\n        if (in_array($originalFormat, ['JPEG', 'TIFF', 'TIF'])) {\n            $image->setExif($this->extractExifData($path));\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":80,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php#L45-L80","documentation":"After Imagick::readImage() succeeded, Imagick::getImageFormat() threw. This is an unusual mid-decode state: ImageMagick opened the container but the resulting Imagick object exposes no image format. Unlike the sibling error at line 55, the native exception is preserved as previous, so the real ImageMagick reason is recoverable via getPrevious().","triggerScenarios":"Reading a file whose header parses but whose image list ends up empty or unreadable: truncated progressive JPEG, multi-page container where inner coders are policy-blocked, some RAW/DNG variants where only the container coder exists.","commonSituations":"Truncated multi-page TIFFs in document pipelines; partially-written files from a crashed producer; exotic formats on minimal ImageMagick builds.","solutions":["Inspect the chained native error: catch ImageDecoderException and read $e->getPrevious()?->getMessage() for the true ImageMagick reason","Run `identify -verbose file` on the command line to see whether ImageMagick itself can enumerate a format","Re-save the file externally in a baseline format (convert in.tif out.png) and read that instead","If the previous exception indicates an internal ImageMagick bug, upgrade ImageMagick/imagick"],"exampleFix":"// before\n$image = $manager->read('truncated.tif');\n\n// after: surface the native ImageMagick reason\ntry {\n    $image = $manager->read('truncated.tif');\n} catch (ImageDecoderException $e) {\n    $reason = $e->getPrevious()?->getMessage() ?? 'no native reason';\n    $logger->warning('Format lookup failed: ' . $reason);\n    throw $e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read($path);\n} catch (\\Intervention\\Image\\Exceptions\\ImageDecoderException $e) {\n    $native = $e->getPrevious()?->getMessage() ?? 'unknown';\n    $logger->warning('ImageMagick format lookup failed: ' . $native);\n    throw $e;\n}","preventionTips":["Always log getPrevious() - this error chains the native ImageMagick reason","Smoke-test exotic formats with `identify` before adding them to accepted upload types"],"tags":["imagick","metadata","image-format","decode"],"backgroundTag":"image-metadata-unavailable","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}