{"record":{"id":"95ae828ac654b9e7","repo":"Intervention/image","slug":"failed-to-apply-class-unable-to-preserve-icc-pr","errorCode":null,"errorMessage":"Failed to apply {class}, unable to preserve icc profiles","messagePattern":"Failed to apply (.+?), unable to preserve icc profiles","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/StripMetaModifier.php","lineNumber":29,"sourceCode":"use Intervention\\Image\\Interfaces\\ModifierInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\n\nclass StripMetaModifier implements ModifierInterface, SpecializedInterface\n{\n    /**\n     * {@inheritdoc}\n     *\n     * @see Intervention\\Image\\Interfaces\\ModifierInterface::apply()\n     *\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        // preserve icc profiles\n        try {\n            $profiles = $image->core()->native()->getImageProfiles('icc');\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to preserve icc profiles',\n                previous: $e,\n            );\n        }\n\n        // remove meta data\n        try {\n            $result = $image->core()->native()->stripImage();\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to strip meta data',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to strip meta data',\n                previous: $e,\n            );","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/StripMetaModifier.php#L11-L47","documentation":"First failure step of the Imagick StripMetaModifier: Imagick::getImageProfiles('icc') threw while reading the embedded ICC profile so it can be re-applied after stripping. The Imagick encoders run this modifier automatically when strip: true is set (Jpeg, Webp, Avif, Heic, Tiff, Jxl, Jpeg2000), so it usually surfaces during encoding rather than from explicit metadata stripping.","triggerScenarios":"$image->encode(new WebpEncoder(quality: 85, strip: true)) (or any Imagick encoder with strip: true, or modify(new StripMetaModifier())) when getImageProfiles('icc') throws - malformed/partial ICC blob in the source, corrupted image state, or an ImageMagick build without working profile support.","commonSituations":"Enabling strip on untrusted user uploads; images with broken embedded ICC profiles; ImageMagick installations compiled without the LCMS delegate; batch jobs where one poisoned file fails the encode step.","solutions":["Read getPrevious() for the underlying ImagickException message to confirm the profile read is the failing step","Try encoding without strip: true - if that works, the source profile blob is the problem","Pre-clean or re-save the offending image externally (exiftool/mogrify) before upload","Verify ImageMagick was built with LCMS delegate support (convert -list delegate | grep -i lcms)"],"exampleFix":"// before\n$encoded = $image->encode(new WebpEncoder(quality: 85, strip: true));\n\n// after\ntry {\n    $encoded = $image->encode(new WebpEncoder(quality: 85, strip: true));\n} catch (ModifierException $e) {\n    $reason = $e->getPrevious()?->getMessage() ?? $e->getMessage();\n    $logger->warning('Strip failed, encoding with metadata: ' . $reason);\n    $encoded = $image->encode(new WebpEncoder(quality: 85));\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $encoded = $image->encode(new WebpEncoder(quality: 85, strip: true));\n} catch (ModifierException $e) {\n    $reason = $e->getPrevious()?->getMessage() ?? $e->getMessage();\n    $logger->warning('Strip/ICC step failed: ' . $reason);\n    $encoded = $image->encode(new WebpEncoder(quality: 85)); // metadata kept\n}","preventionTips":["Screen uploads with exiftool/identify before enabling strip on them","Ensure ImageMagick is compiled with the LCMS delegate in production images","Log getPrevious() messages so profile failures are diagnosable from production"],"tags":["imagick","icc-profile","metadata","encoding","strip"],"backgroundTag":"imagick-operation-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}