Intervention/image · error · Intervention\Image\Exceptions\ModifierException
Failed to apply {class}, unable to adjust image gamma
Error message
Failed to apply {class}, unable to adjust image gamma What it means
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.
Source
Thrown at src/Drivers/Imagick/Modifiers/GammaModifier.php:24
use ImagickException;
use Intervention\Image\Exceptions\ModifierException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\GammaModifier as GenericGammaModifier;
class GammaModifier extends GenericGammaModifier implements SpecializedInterface
{
/**
* @throws ModifierException
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
try {
$result = $frame->native()->gammaImage($this->gamma);
if ($result === false) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to adjust image gamma',
);
}
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to adjust image gamma',
previous: $e,
);
}
}
return $image;
}
}
View on GitHub (pinned to 5598b9e397)
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
Example fix
// before
$image->gamma($request->float('gamma')); // 0, -2 or 1e30 pass straight through
// after
$gamma = $request->float('gamma');
$gamma = min(10.0, max(0.1, (float) $gamma)); // clamp to 0.1..10
if (!is_finite($gamma)) {
$gamma = 1.0;
}
$image->gamma($gamma); Defensive patterns
Strategy: validation
Validate before calling
$gamma = (float) $gamma;
if (!is_finite($gamma) || $gamma < 0.1) {
$gamma = 1.0; // neutral fallback
}
$gamma = min(10.0, $gamma); // clamp upper bound
$image->gamma($gamma); Type guard
function isValidGamma(mixed $value): bool
{
return is_int($value) || is_float($value)
? is_finite($value) && $value >= 0.1 && $value <= 10.0
: false;
} Try / catch
use Intervention\Image\Exceptions\ModifierException;
try {
$image->gamma($gamma);
} catch (ModifierException $e) {
Log::warning('Gamma failed for value ' . var_export($gamma, true));
$image->gamma(1.0); // neutral retry
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to apply {class}, unable to set image resolution
- Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
- Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
- Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
- Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/23220f164d81f99e.
Report an issue: GitHub.