Intervention/image · error · Intervention\Image\Exceptions\ModifierException
Failed to apply {class}, unable to set image resolution
Error message
Failed to apply {class}, unable to set image resolution What it means
setResolution() forwards the DPI values to Imagick::setImageResolution($x, $y); a false return triggers this ModifierException. The generic ResolutionModifier constructor stores the floats without validating them, so zero or negative resolutions reach ImageMagick, which requires strictly positive values. This false-return branch is the rarer path; invalid resolutions more often throw ImagickException (sibling catch).
Source
Thrown at src/Drivers/Imagick/Modifiers/ResolutionModifier.php:25
use ImagickException;
use Intervention\Image\Exceptions\ModifierException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ResolutionModifier as GenericResolutionModifier;
class ResolutionModifier extends GenericResolutionModifier implements SpecializedInterface
{
/**
* @throws ModifierException
*/
public function apply(ImageInterface $image): ImageInterface
{
$imagick = $image->core()->native();
try {
$result = $imagick->setImageResolution($this->x, $this->y);
if ($result === false) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to set image resolution',
);
}
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to set image resolution',
previous: $e,
);
}
return $image;
}
}
View on GitHub (pinned to 5598b9e397)
Solutions
- Validate before calling: both x and y must be > 0
- Default missing metadata to a sane DPI (72 for screen, 300 for print) instead of 0
- Enforce numeric bounds (min:0.01 or min:1) on user-supplied DPI at the request boundary
- If the call still fails, inspect the chained previous exception for the native wording
Example fix
// before $image->setResolution($sourceDpi, $sourceDpi); // 0 when metadata absent // after $dpi = $sourceDpi > 0 ? $sourceDpi : 72.0; $image->setResolution($dpi, $dpi);
Defensive patterns
Strategy: validation
Validate before calling
if ($x <= 0 || $y <= 0) {
throw new \InvalidArgumentException(sprintf('Resolution must be positive, got %F x %F', $x, $y));
}
$image->setResolution($x, $y); Type guard
function isValidResolution(float $x, float $y): bool
{
return $x > 0 && $y > 0;
} Prevention
- Default missing DPI metadata to 72 (screen) or 300 (print) instead of letting 0 through
- Validate DPI form fields with numeric min:1 rules
- Remember the library does not pre-validate x/y; the caller owns this invariant
When it happens
Trigger: $image->setResolution(0, 72), setResolution(-1, -1), or DPI values computed from user input / EXIF / PDF metadata that can be 0.
Common situations: Export code copying resolution from a source whose metadata is missing (defaults to 0); PDF/EPS workflows where 0 DPI sneaks in; forms letting users type 0 into a DPI field.
Related errors
- Failed to apply {class}, unable to adjust image gamma
- Failed to read 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
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/11ca2d5463a1bbd0.
Report an issue: GitHub.