{"record":{"id":"1d28e0bfd3d285a0","repo":"Intervention/image","slug":"failed-to-apply-intervention-image-drivers-imagick-1d28e0","errorCode":null,"errorMessage":"Failed to apply Intervention\\Image\\Drivers\\Imagick\\Modifiers\\FillModifier, unable to build ImagickDraw object","messagePattern":"Failed to apply Intervention\\\\Image\\\\Drivers\\\\Imagick\\\\Modifiers\\\\FillModifier, unable to build ImagickDraw object","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/FillModifier.php","lineNumber":96,"sourceCode":"            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to flood fill image',\n                previous: $e,\n            );\n        }\n    }\n\n    /**\n     * @throws ModifierException\n     */\n    private function fillAllWithColor(Imagick $frame, ImagickPixel $pixel): void\n    {\n        try {\n            $draw = new ImagickDraw();\n            $draw->setFillColor($pixel);\n            $draw->rectangle(0, 0, $frame->getImageWidth(), $frame->getImageHeight());\n            $frame->drawImage($draw);\n        } catch (ImagickException | ImagickDrawException | ImagickPixelException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to build ImagickDraw object',\n                previous: $e,\n            );\n        }\n\n        try {\n            // deactive alpha channel when image was filled with opaque color\n            if ($pixel->getColorValue(Imagick::COLOR_ALPHA) === 1.0) {\n                $result = $frame->setImageAlphaChannel(Imagick::ALPHACHANNEL_DEACTIVATE);\n                if ($result === false) {\n                    throw new ModifierException(\n                        'Failed to apply ' . self::class . ', unable to adjust alpha channel',\n                    );\n                }\n            }\n        } catch (ImagickException | ImagickPixelException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to adjust alpha channel',","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/FillModifier.php#L78-L114","documentation":"This ModifierException is thrown when a full-canvas fill ($image->fill($color) without a position) fails while drawing the cover rectangle. The Imagick driver builds an ImagickDraw, sets your color as fill, draws rectangle(0,0,width,height) and calls drawImage(); any ImagickException, ImagickDrawException or ImagickPixelException from that sequence is wrapped as 'unable to build ImagickDraw object'.","triggerScenarios":"Calling $image->fill($color) on images whose dimensions exceed ImageMagick's policy-limited width/height/area; filling with a color object that produced a broken ImagickPixel; drawing on a corrupted frame whose pixel cache cannot be locked for writing; extremely constrained memory environments.","commonSituations":"Filling large uploaded images on shared hosting where policy.xml caps image area far below the uploaded size; filling images decoded from truncated files; hosts with very low memory_limit where allocating the draw wand fails; color values passed as unusual formats that decode to pixels the installed ImageMagick rejects.","solutions":["Inspect $e->getPrevious() to get the underlying Imagick/ImagickDraw/ImagickPixel error","Downscale oversized images before filling, or raise the width/height/area limits in policy.xml","Verify the color argument is a valid color string or ColorInterface (test with a simple hex like 'ff0000')","Re-encode or re-save corrupt sources before processing","Increase PHP memory_limit if allocation failures appear in the previous exception"],"exampleFix":"// before\n$image = $manager->read('poster.tif');\n$image->fill('4a90d9');\n\n// after (guard oversized input)\n$image = $manager->read('poster.tif');\n$maxPixels = 40_000_000;\nif ($image->width() * $image->height() > $maxPixels) {\n    $image->scaleDown(width: 6000);\n}\n$image->fill('4a90d9');","handlingStrategy":"try-catch","validationCode":"$pixelCount = $image->width() * $image->height();\nif ($pixelCount > 40_000_000) {\n    $image->scaleDown(width: 6000);\n}\n$image->fill($color);","typeGuard":"function isFillColorValid(string|\\Intervention\\Image\\Interfaces\\ColorInterface $color): bool\n{\n    if ($color instanceof \\Intervention\\Image\\Interfaces\\ColorInterface) {\n        return true;\n    }\n    return (bool) preg_match('/^([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8}|rgba?\\([^)]*\\))$/i', trim($color, \"# \\t\\n\\r\"));\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->fill($color);\n} catch (ModifierException $e) {\n    Log::error('Full fill failed: ' . optional($e->getPrevious())->getMessage());\n    throw $e;\n}","preventionTips":["Validate color strings before passing them to fill()","Downscale oversized images or raise policy.xml limits before fills","Re-encode corrupted uploads (validate with a re-decode round-trip)","Test fills with a simple hex color to separate color problems from image problems"],"tags":["intervention-image","imagick","fill","imagickdraw","resource-limits","php"],"backgroundTag":"imagick-draw-object-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}