{"record":{"id":"23220f164d81f99e","repo":"Intervention/image","slug":"failed-to-apply-class-unable-to-adjust-image-ga","errorCode":null,"errorMessage":"Failed to apply {class}, unable to adjust image gamma","messagePattern":"Failed to apply (.+?), unable to adjust image gamma","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/GammaModifier.php","lineNumber":24,"sourceCode":"\nuse ImagickException;\nuse Intervention\\Image\\Exceptions\\ModifierException;\nuse Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\nuse Intervention\\Image\\Modifiers\\GammaModifier as GenericGammaModifier;\n\nclass GammaModifier extends GenericGammaModifier implements SpecializedInterface\n{\n    /**\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        foreach ($image as $frame) {\n            try {\n                $result = $frame->native()->gammaImage($this->gamma);\n                if ($result === false) {\n                    throw new ModifierException(\n                        'Failed to apply ' . self::class . ', unable to adjust image gamma',\n                    );\n                }\n            } catch (ImagickException $e) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to adjust image gamma',\n                    previous: $e,\n                );\n            }\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":6,"sourceCodeEnd":39,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/GammaModifier.php#L6-L39","documentation":"This ModifierException is thrown by $image->gamma($value) when the native gamma correction reports failure by returning false. The Imagick driver calls gammaImage($this->gamma) on every frame; a false return means ImageMagick refused the gamma value or could not apply it, and the driver converts it to 'unable to adjust image gamma' without a chained previous exception.","triggerScenarios":"Calling $image->gamma($g) with a value outside the range accepted by ImageMagick (values <= 0, or extreme magnitudes); applying gamma to frames whose pixel cache cannot be processed under current resource limits; policy-restricted environments blocking channel-wide operations.","commonSituations":"User-supplied gamma values (e.g. from an editing UI slider) passed through without range validation; gamma 0 or negative values from arithmetic that should be clamped; processing very large images near memory limits; shared hosts restricting ImageMagick operations.","solutions":["Clamp gamma to a sane positive range (commonly 0.1 to 10) before calling gamma()","Check the value is a finite number (not NAN/INF) before use","Downscale very large images or raise resource limits if the value is valid but the op fails","Inspect ImageMagick policy.xml if valid values still fail","Compare with the GD driver to isolate environment-specific failures"],"exampleFix":"// before\n$image->gamma($request->float('gamma')); // 0, -2 or 1e30 pass straight through\n\n// after\n$gamma = $request->float('gamma');\n$gamma = min(10.0, max(0.1, (float) $gamma)); // clamp to 0.1..10\nif (!is_finite($gamma)) {\n    $gamma = 1.0;\n}\n$image->gamma($gamma);","handlingStrategy":"validation","validationCode":"$gamma = (float) $gamma;\nif (!is_finite($gamma) || $gamma < 0.1) {\n    $gamma = 1.0; // neutral fallback\n}\n$gamma = min(10.0, $gamma); // clamp upper bound\n$image->gamma($gamma);","typeGuard":"function isValidGamma(mixed $value): bool\n{\n    return is_int($value) || is_float($value)\n        ? is_finite($value) && $value >= 0.1 && $value <= 10.0\n        : false;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->gamma($gamma);\n} catch (ModifierException $e) {\n    Log::warning('Gamma failed for value ' . var_export($gamma, true));\n    $image->gamma(1.0); // neutral retry\n}","preventionTips":["Clamp user-supplied gamma to 0.1–10 before calling gamma()","Reject NAN/INF early — they pass PHP float checks but break ImageMagick","Treat gamma 0 or negative as invalid input at the boundary","Remember this variant carries no previous exception; the value is your first suspect"],"tags":["intervention-image","imagick","gamma","color-correction","input-validation","php"],"backgroundTag":"imagick-gamma-adjust-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}