Intervention/image · error · Intervention\Image\Exceptions\NotSupportedException

No modifier for {$drawable::class} found

Error message

No modifier for {$drawable::class} found

What it means

Image::draw() dispatches to a modifier via a match on the concrete drawable class: Rectangle, Circle/Ellipse, Bezier, Line and Polygon are supported. Any other DrawableInterface implementation — including subclasses of the built-in ones, since the match is on ::class, not instanceof — falls to the default arm and throws NotSupportedException. Custom drawable shapes are not extensible through this entry point.

Source

Thrown at src/Image.php:1142

    /**
     * {@inheritdoc}
     *
     * @see ImageInterface::draw()
     *
     * @throws InvalidArgumentException
     * @throws NotSupportedException
     * @throws ModifierException
     * @throws ColorDecoderException
     */
    public function draw(DrawableInterface $drawable): ImageInterface
    {
        return $this->modify(match ($drawable::class) {
            Rectangle::class => new DrawRectangleModifier($drawable),
            Circle::class, Ellipse::class => new DrawEllipseModifier($drawable),
            Bezier::class => new DrawBezierModifier($drawable),
            Line::class => new DrawLineModifier($drawable),
            Polygon::class => new DrawPolygonModifier($drawable),
            default => throw new NotSupportedException('No modifier for ' . $drawable::class . ' found'),
        });
    }

    /**
     * {@inheritdoc}
     *
     * @see ImageInterface::encode()
     *
     * @throws EncoderException
     */
    public function encode(?EncoderInterface $encoder = null): EncodedImageInterface
    {
        return $this->driver()->specializeEncoder(
            $encoder ?: new AutoEncoder(),
        )->encode($this);
    }

    /**

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Use the built-in drawable classes (Rectangle, Ellipse, Circle, Bezier, Line, Polygon) and configure them via their setters instead of subclassing
  2. If you need custom rendering, write a custom Modifier and invoke it via $image->modify(new MyModifier()) directly
  3. Pass the exact built-in class, not a subclass, to draw()
  4. Pin/upgrade the intervention/image version so the drawable classes you reference exist in the match list

Example fix

// before
$image->draw(new class extends Rectangle { /* ... */ }); // NotSupportedException

// after
$image->draw((new Rectangle(100, 100))->setBackgroundColor('f00'));
// or custom rendering:
$image->modify(new DrawCustomShapeModifier($customData));
Defensive patterns

Strategy: type-guard

Validate before calling

$supported = [Rectangle::class, Ellipse::class, Circle::class, Bezier::class, Line::class, Polygon::class];
if (!in_array($drawable::class, $supported, true)) {
    throw new InvalidArgumentException('Unsupported drawable: ' . $drawable::class);
}
$image->draw($drawable);

Type guard

function isBuiltInDrawable(object $drawable): bool
{
    return in_array($drawable::class, [
        \Intervention\Image\Geometry\Rectangle::class,
        \Intervention\Image\Geometry\Ellipse::class,
        \Intervention\Image\Geometry\Circle::class,
        \Intervention\Image\Geometry\Bezier::class,
        \Intervention\Image\Geometry\Line::class,
        \Intervention\Image\Geometry\Polygon::class,
    ], true); // exact class match — subclasses are NOT supported
}

Try / catch

try {
    $image->draw($shape);
} catch (NotSupportedException $e) {
    // programming error: switch to a built-in shape or a custom Modifier
}

Prevention

When it happens

Trigger: $image->draw(new MyCustomShape()) where MyCustomShape implements DrawableInterface but is none of the five known classes; also new class RectangleSubclass() (match on $drawable::class does not match the parent case).

Common situations: Upgrading custom code from older Intervention versions where shapes were extensible, or writing a custom drawable expecting polymorphic dispatch. Version changes that introduce new drawable classes not present in the installed release can also surface this.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/6e640f2a8d94b1e6. Report an issue: GitHub.