{"record":{"id":"0098ece40c43f231","repo":"Intervention/image","slug":"failed-to-apply-intervention-image-drivers-imagick-0098ec","errorCode":null,"errorMessage":"Failed to apply Intervention\\Image\\Drivers\\Imagick\\Modifiers\\FillModifier, unable to find target flood fill color","messagePattern":"Failed to apply Intervention\\\\Image\\\\Drivers\\\\Imagick\\\\Modifiers\\\\FillModifier, unable to find target flood fill color","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/FillModifier.php","lineNumber":55,"sourceCode":"                $this->fillAllWithColor($frame, $pixel);\n            }\n        }\n\n        return $image;\n    }\n\n    /**\n     * @throws ModifierException\n     */\n    private function floodFillWithColor(Imagick $frame, ImagickPixel $pixel): void\n    {\n        try {\n            $target = $frame->getImagePixelColor(\n                $this->position->x(),\n                $this->position->y(),\n            );\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to find target flood fill color',\n                previous: $e,\n            );\n        }\n\n        try {\n            $result = $frame->floodFillPaintImage(\n                $pixel,\n                100,\n                $target,\n                $this->position->x(),\n                $this->position->y(),\n                false,\n                Imagick::CHANNEL_ALL,\n            );\n\n            if ($result === false) {\n                throw new ModifierException(","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/FillModifier.php#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n$image->fill('ff5500', $request->input('x'), $request->input('y'));\n\n// after\n$x = (int) $request->input('x');\n$y = (int) $request->input('y');\nif ($x < 0 || $y < 0 || $x >= $image->width() || $y >= $image->height()) {\n    $x = (int) floor($image->width() / 2);\n    $y = (int) floor($image->height() / 2);\n}\n$image->fill('ff5500', $x, $y);","handlingStrategy":"validation","validationCode":"$x = (int) $x;\n$y = (int) $y;\n$inBounds = $x >= 0 && $y >= 0 && $x < $image->width() && $y < $image->height();\nif (! $inBounds) {\n    // choose: clamp, center, or reject\n    $x = (int) floor($image->width() / 2);\n    $y = (int) floor($image->height() / 2);\n}\n$image->fill($color, $x, $y);","typeGuard":"function fillPositionInBounds(\\Intervention\\Image\\Interfaces\\ImageInterface $image, int $x, int $y): bool\n{\n    return $x >= 0 && $y >= 0 && $x < $image->width() && $y < $image->height();\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->fill($color, $x, $y);\n} catch (ModifierException $e) {\n    if (str_contains($e->getMessage(), 'unable to find target flood fill color')) {\n        $image->fill($color, (int) floor($image->width() / 2), (int) floor($image->height() / 2));\n    } else {\n        throw $e;\n    }\n}","preventionTips":["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"],"tags":["intervention-image","imagick","flood-fill","pixel-color","out-of-bounds","php"],"backgroundTag":"flood-fill-seed-out-of-bounds","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}