{"record":{"id":"d9bcc801ed8c3ae1","repo":"Intervention/image","slug":"failed-to-apply-class-unable-to-set-icc-color-p","errorCode":null,"errorMessage":"Failed to apply {class}, unable to set ICC color profile","messagePattern":"Failed to apply (.+?), unable to set ICC color profile","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/ProfileModifier.php","lineNumber":25,"sourceCode":"use ImagickException;\nuse Intervention\\Image\\Exceptions\\ModifierException;\nuse Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\nuse Intervention\\Image\\Modifiers\\ProfileModifier as GenericProfileModifier;\n\nclass ProfileModifier extends GenericProfileModifier implements SpecializedInterface\n{\n    /**\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        $imagick = $image->core()->native();\n\n        try {\n            $result = $imagick->profileImage('icc', (string) $this->profile);\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to set ICC color profile',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to set ICC color profile',\n                previous: $e,\n            );\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":39,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/ProfileModifier.php#L7-L39","documentation":"setProfile() passes the profile binary to Imagick::profileImage('icc', $binary); a false return triggers this ModifierException. Typical native causes: the payload is not a valid ICC profile (truncated download, wrong file), or the profile's color space does not match the image data, e.g. assigning a CMYK profile to RGB pixels. The false branch is the rarer path; invalid profiles more often throw ImagickException (covered by the sibling catch).","triggerScenarios":"$image->setProfile(Profile::fromPath($path)) where the file is not a real ICC profile, or applying a print CMYK profile (e.g. FOGRA/US Web Coated) to an sRGB image without converting first.","commonSituations":"Letting users upload .icc files and assigning them verbatim; ImageMagick built without the LCMS delegate so profile handling silently degrades; mismatched profile chains when moving assets between print and web pipelines.","solutions":["Validate the binary before assignment: an ICC file has the signature 'acsp' at byte offset 36","Use a known-good profile such as sRGB IEC61966-2.1 for web output instead of user-supplied files","For CMYK<->RGB work, convert the colorspace ($image->colorspace(...)) or profileImage in the correct direction rather than swapping profiles on mismatched data","Confirm the LCMS delegate exists: convert -list configure | grep -i lcms, and rebuild/install ImageMagick with lcms if missing"],"exampleFix":"// before\n$image->setProfile(\\Intervention\\Image\\Colors\\Profile::fromPath($uploadedIcc));\n\n// after\n$binary = (string) file_get_contents($uploadedIcc);\nif (strlen($binary) < 128 || substr($binary, 36, 4) !== 'acsp') {\n    throw new RuntimeException('The uploaded file is not a valid ICC profile');\n}\n$image->setProfile(new \\Intervention\\Image\\Colors\\Profile($binary));","handlingStrategy":"try-catch","validationCode":"$binary = (string) file_get_contents($iccPath);\n$isValidIcc = strlen($binary) >= 128 && substr($binary, 36, 4) === 'acsp';\nif (!$isValidIcc) {\n    throw new \\RuntimeException('Not a valid ICC profile: ' . $iccPath);\n}\n$image->setProfile(new \\Intervention\\Image\\Colors\\Profile($binary));","typeGuard":"function isValidIccProfile(string $binary): bool\n{\n    return strlen($binary) >= 128 && substr($binary, 36, 4) === 'acsp';\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->setProfile($profile);\n} catch (ModifierException $e) {\n    // bad binary / delegate missing / colorspace mismatch -> keep original profile and continue\n    $logger->warning('Profile apply failed: ' . $e->getPrevious()?->getMessage());\n}","preventionTips":["Ship known-good profiles (e.g. sRGB IEC61966-2.1) with your app instead of accepting user .icc uploads","Match profile colorspace to pixel data: convert before assigning a CMYK/print profile","Confirm LCMS support on every deploy target (convert -list configure | grep -i lcms)"],"tags":["php","imagick","intervention-image","icc-profile","color-management","lcms"],"backgroundTag":"icc-profile-apply-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}