{"record":{"id":"d2558da4c552587e","repo":"Intervention/image","slug":"failed-to-apply-self-class-unable-to-dra-d2558d","errorCode":null,"errorMessage":"Failed to apply ' . self::class . ', unable to draw pixel on image","messagePattern":"Failed to apply ' \\. self::class \\. ', unable to draw pixel on image","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Traits/CanDraw.php","lineNumber":25,"sourceCode":"use Imagick;\nuse ImagickDraw;\nuse ImagickException;\nuse Intervention\\Image\\Exceptions\\ModifierException;\n\ntrait CanDraw\n{\n    /**\n     * Draw given element on canvas.\n     *\n     * @throws ModifierException\n     */\n    protected function draw(Imagick $canvas, ImagickDraw $element): void\n    {\n        try {\n            $result = $canvas->drawImage($element);\n\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to draw pixel on image',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to draw pixel on image',\n                previous: $e,\n            );\n        }\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":37,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Traits/CanDraw.php#L7-L37","documentation":"ModifierException from the Imagick CanDraw trait, false-return variant: Imagick::drawImage($element) returned false while rendering a shape, so nothing was drawn. The trait is shared by DrawPixelModifier, DrawLineModifier, DrawPolygonModifier, DrawBezierModifier, DrawEllipseModifier and DrawRectangleModifier, so every shape-drawing API funnels through this single check.","triggerScenarios":"$image->drawRectangle(...), drawEllipse(), drawLine(), drawPolygon(), drawBezier() or a pixel draw on the Imagick driver when drawImage() returns false - typically because the ImagickDraw element is in an unusable state (bad font/color setup, invalid primitive) or the canvas frame is invalid.","commonSituations":"Drawing shapes on blank/programmatically created images whose frame native object is incomplete; draw elements configured with values some ImageMagick builds reject; reusing an image after an earlier modifier failure.","solutions":["Verify the target image decodes or is created properly and has pixel data before drawing","Simplify the shape configuration (plain opaque colors, simple coordinates) to find the rejected property","Reproduce with a raw Imagick script calling drawImage() on the same element","Catch ModifierException and log the shape parameters plus getPrevious() for diagnosis"],"exampleFix":"// before\n$image->drawRectangle(function ($rectangle) {\n    $rectangle->background('rgba(255, 0, 0, 0)'); // drawImage() returns false\n});\n\n// after\n$image->drawRectangle(function ($rectangle) {\n    $rectangle->background('#ff0000');\n});","handlingStrategy":"try-catch","validationCode":"// draw only on images that hold pixel data\nif ($image->count() === 0 || $image->width() < 1 || $image->height() < 1) {\n    throw new InvalidArgumentException('Canvas has no pixel data to draw on');\n}","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->drawRectangle($callback);\n} catch (ModifierException $e) {\n    $logger->warning('Shape draw returned failure: ' . $e->getMessage());\n    // overlays are often optional - continue without the shape if acceptable\n}","preventionTips":["Create canvases via the driver's create() helpers so frames always have pixel data","Use plain opaque hex colors for shape backgrounds and borders","Draw overlays early on a freshly decoded/created image"],"tags":["imagick","drawing","shapes","modifier"],"backgroundTag":"imagick-operation-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}