Intervention/image · error · Intervention\Image\Exceptions\ModifierException
Failed to resize image
Error message
Failed to resize image
What it means
Image::resize() wraps dimension resolution and the ResizeModifier in a try/catch that converts any AnalyzerException into ModifierException('Failed to resize image'). The analyzer call happens in resolveDimension(): when width or height is a Fraction enum (e.g. Fraction::HALF), it must read the current image size via size() — if that analysis fails, the error is wrapped here with the original exception as previous. Plain invalid ints (like both null) throw a different, unwrapped InvalidArgumentException from ResizeModifier.
Source
Thrown at src/Image.php:707
FontFactory::build($font),
),
);
}
/**
* {@inheritdoc}
*
* @see ImageInterface::resize()
*
* @throws InvalidArgumentException
* @throws ModifierException
*/
public function resize(null|int|Fraction $width = null, null|int|Fraction $height = null): ImageInterface
{
try {
return $this->modify(new ResizeModifier(...$this->resolveDimension($width, $height)));
} catch (AnalyzerException $e) {
throw new ModifierException('Failed to resize image', previous: $e);
}
}
/**
* {@inheritdoc}
*
* @see ImageInterface::resizeDown()
*
* @throws InvalidArgumentException
* @throws ModifierException
*/
public function resizeDown(null|int|Fraction $width = null, null|int|Fraction $height = null): ImageInterface
{
try {
return $this->modify(new ResizeDownModifier(...$this->resolveDimension($width, $height)));
} catch (AnalyzerException $e) {
throw new ModifierException('Failed to resize image', previous: $e);
}View on GitHub (pinned to 5598b9e397)
Solutions
- Read $e->getPrevious() — the original AnalyzerException tells you what actually failed
- If using Fraction arguments, verify $image->width() and $image->height() succeed before resizing
- Re-read the image from its original source; discard objects with inconsistent state
- Convert relative sizes to absolute ints yourself (compute from $image->size()) to bypass the analyzer path
Example fix
// before $image->resize(Fraction::HALF, null); // ModifierException if size analysis fails // after $size = $image->size(); // fail early, clear error $image->resize((int) round($size->width() / 2), null);
Defensive patterns
Strategy: try-catch
Validate before calling
try {
$size = $image->size();
} catch (AnalyzerException) {
return reject('source image dimensions unreadable');
}
// only now use resize(), optionally with Fraction Type guard
function canResolveFractions(ImageInterface $image): bool
{
try { $image->size(); return true; }
catch (\Throwable) { return false; }
} Try / catch
try {
$image->resize(Fraction::HALF);
} catch (ModifierException $e) {
$cause = $e->getPrevious(); // AnalyzerException with the real failure
} Prevention
- Verify size() before Fraction-based resizing
- Compute absolute ints from a verified size to skip the analyzer path
- In pipelines, catch per-image and quarantine rather than aborting the batch
When it happens
Trigger: $image->resize(Fraction::HALF, null) (or any Fraction argument) on an image whose width()/height() analysis or Size construction fails; see the size() entry for how that happens. resize(300, 200) with plain ints does not reach the analyzer and cannot produce this message.
Common situations: Percentage-style resizing (Fraction enums) applied to corrupted or inconsistent image cores, chained operations after a partially failed decode, or images from a problematic source file. The wrapper obscures the root cause, so developers see 'Failed to resize image' without the underlying analyzer error.
Related errors
- Failed to invert color
- Percentage value must be between -100 and 100
- Color channel {class} value must be in range {min} to {max}
- Unable to parse CMYK color from input "{input}"
- Class '{objectShortname}' is not supported by {id} driver
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/f779140a8fc22e88.
Report an issue: GitHub.