{"record":{"id":"c58697aa89ac9672","repo":"Intervention/image","slug":"failed-to-apply-intervention-image-drivers-imagick-c58697","errorCode":null,"errorMessage":"Failed to apply Intervention\\Image\\Drivers\\Imagick\\Modifiers\\ColorizeModifier, unable to adjust image colors","messagePattern":"Failed to apply Intervention\\\\Image\\\\Drivers\\\\Imagick\\\\Modifiers\\\\ColorizeModifier, unable to adjust image colors","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/ColorizeModifier.php","lineNumber":41,"sourceCode":"        $blue = $this->normalizeLevel($this->blue);\n\n        foreach ($image as $frame) {\n            try {\n                $qrange = $frame->native()->getQuantumRange();\n            } catch (ImageException $e) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to get quantum range',\n                    previous: $e,\n                );\n            }\n\n            try {\n                $result = $frame->native()->levelImage(0, $red, $qrange['quantumRangeLong'], Imagick::CHANNEL_RED)\n                    && $frame->native()->levelImage(0, $green, $qrange['quantumRangeLong'], Imagick::CHANNEL_GREEN)\n                    && $frame->native()->levelImage(0, $blue, $qrange['quantumRangeLong'], Imagick::CHANNEL_BLUE);\n\n                if ($result === false) {\n                    throw new ModifierException(\n                        'Failed to apply ' . self::class . ', unable to adjust image colors',\n                    );\n                }\n            } catch (ImageException $e) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to adjust image colors',\n                    previous: $e,\n                );\n            }\n        }\n\n        return $image;\n    }\n\n    private function normalizeLevel(int $level): int\n    {\n        return $level > 0 ? intval(round($level / 5)) : intval(round(($level + 100) / 100));\n    }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/ColorizeModifier.php#L23-L59","documentation":"Thrown by the Imagick ColorizeModifier when the chained per-channel levelImage() calls (red && green && blue, bounded by the quantum range) return false during $image->colorize(). A false from any single channel triggers it, so one failing channel aborts the whole modifier. Levels are normalized from -100..100 to black/white points before the call.","triggerScenarios":"Calling $image->colorize() where ImageMagick's levelImage reports failure for a channel: degraded wand state, images in colorspaces where per-channel leveling is unsupported, or resource exhaustion mid-operation. The false-return path carries no previous exception.","commonSituations":"Colorizing CMYK or exotic-colorspace images; processing very large images under tight policy.xml limits; colorizing frames of partially corrupt animated files.","solutions":["Convert to sRGB before colorizing: $image->colorspace(RgbColorspace) — per-channel RGB leveling is the tested path.","If dimensions are extreme, raise ImageMagick resource limits or operate on a scaled copy.","Confirm the source decodes fully; re-encode uploads once before filter chains.","Update ImageMagick if ordinary RGB colorize fails reproducibly (CLI check: convert in.png -level 0,255,1 out.png)."],"exampleFix":"// before\n$image->colorize(80, 0, 0); // channel leveling fails on CMYK source\n\n// after\n$image->colorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class)->colorize(80, 0, 0);","handlingStrategy":"fallback","validationCode":"// avoid the common per-channel failure mode up front\nif (!$image->colorspace() instanceof \\Intervention\\Image\\Colors\\Rgb\\Colorspace) {\n    $image = $image->colorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class);\n}","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\ntry {\n    $image->colorize(50, 25, 0);\n} catch (ModifierException $e) {\n    try {\n        $image->colorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class)->colorize(50, 25, 0);\n    } catch (ModifierException $e2) {\n        throw $e2;\n    }\n}","preventionTips":["Convert to sRGB before colorize on mixed-format pipelines.","Re-encode untrusted uploads once so corrupt channel data fails early and cheaply."],"tags":["imagick","colorize","channels","modifier-exception","colourspace"],"backgroundTag":"image-modifier-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}