Intervention/image · error · ModifierException
Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
Error message
Failed to apply Intervention\Image\Drivers\Imagick\Modifiers\FillModifier, unable to find target flood fill color
What it means
This ModifierException is thrown when a positional fill ($image->fill($color, $x, $y)) cannot read the seed pixel that flood fill needs to match. Before painting, the Imagick driver calls $frame->getImagePixelColor($x, $y) to sample the target color at the fill position; if that native call throws an ImagickException, it is wrapped with the message 'unable to find target flood fill color'. In practice this almost always means the given coordinates lie outside the image canvas.
Source
Thrown at src/Drivers/Imagick/Modifiers/FillModifier.php:55
$this->fillAllWithColor($frame, $pixel);
}
}
return $image;
}
/**
* @throws ModifierException
*/
private function floodFillWithColor(Imagick $frame, ImagickPixel $pixel): void
{
try {
$target = $frame->getImagePixelColor(
$this->position->x(),
$this->position->y(),
);
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to find target flood fill color',
previous: $e,
);
}
try {
$result = $frame->floodFillPaintImage(
$pixel,
100,
$target,
$this->position->x(),
$this->position->y(),
false,
Imagick::CHANNEL_ALL,
);
if ($result === false) {
throw new ModifierException(View on GitHub (pinned to 5598b9e397)
Solutions
- Clamp the fill position to the image: 0 <= x < $image->width() and 0 <= y < $image->height() before calling fill()
- Re-read $image->width()/height() after any resize/crop/orientate and recompute the position
- Cast coordinates to int; floats like 10.7 may not resolve to a valid pixel
- If coordinates are intentionally variable, default the position to the image center when out of range
Example fix
// before
$image->fill('ff5500', $request->input('x'), $request->input('y'));
// after
$x = (int) $request->input('x');
$y = (int) $request->input('y');
if ($x < 0 || $y < 0 || $x >= $image->width() || $y >= $image->height()) {
$x = (int) floor($image->width() / 2);
$y = (int) floor($image->height() / 2);
}
$image->fill('ff5500', $x, $y); Defensive patterns
Strategy: validation
Validate before calling
$x = (int) $x;
$y = (int) $y;
$inBounds = $x >= 0 && $y >= 0 && $x < $image->width() && $y < $image->height();
if (! $inBounds) {
// choose: clamp, center, or reject
$x = (int) floor($image->width() / 2);
$y = (int) floor($image->height() / 2);
}
$image->fill($color, $x, $y); Type guard
function fillPositionInBounds(\Intervention\Image\Interfaces\ImageInterface $image, int $x, int $y): bool
{
return $x >= 0 && $y >= 0 && $x < $image->width() && $y < $image->height();
} Try / catch
use Intervention\Image\Exceptions\ModifierException;
try {
$image->fill($color, $x, $y);
} catch (ModifierException $e) {
if (str_contains($e->getMessage(), 'unable to find target flood fill color')) {
$image->fill($color, (int) floor($image->width() / 2), (int) floor($image->height() / 2));
} else {
throw $e;
}
} Prevention
- Always bounds-check fill coordinates against current width()/height()
- Recompute positions after resize/crop/orientate change image dimensions
- Use width-1 and height-1 as the maximum valid coordinates
- Prefer clamping over trusting user-supplied click positions
When it happens
Trigger: Calling $image->fill('ff0000', $x, $y) with $x < 0 or $x >= $image->width(), or $y < 0 or $y >= $image->height(); using a PointInterface position computed from stale dimensions after a resize/crop; float coordinates passed where the native API expects integers within bounds.
Common situations: Fill coordinates taken from user input (click positions on a front-end canvas) without clamping; positions calculated relative to an older image size after resize(), crop() or orientate() changed the dimensions; off-by-one errors using width/height instead of width-1/height-1 as the maximum coordinate.
Related errors
- 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
- Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/0098ece40c43f231.
Report an issue: GitHub.