Intervention/image · error · DriverException

Failed to create new image

Error message

Failed to create new image

What it means

Imagick::newImage() (or constructing the ImagickPixel background) threw while allocating a blank transparent canvas. Dimensions already passed the >=1 check, so the failure is at the ImageMagick level - overwhelmingly memory/resource exhaustion when the requested canvas is very large. Native error chained as previous.

Source

Thrown at src/Drivers/Imagick/Driver.php:73

     * @see DriverInterface::createImage()
     *
     * @throws InvalidArgumentException
     * @throws DriverException
     */
    public function createImage(int $width, int $height): ImageInterface
    {
        if ($width < 1 || $height < 1) {
            throw new InvalidArgumentException('Invalid image size. Must be int<1, max>');
        }

        try {
            $background = new ImagickPixel('rgba(255, 255, 255, 0)');

            $imagick = new Imagick();
            $imagick->newImage($width, $height, $background, 'png');
            $this->applyDefaultSettings($imagick);
        } catch (ImagickException | ImagickPixelException $e) {
            throw new DriverException('Failed to create new image', previous: $e);
        }

        return new Image($this, new Core($imagick));
    }

    /**
     * {@inheritdoc}
     *
     * @see DriverInterface::createCore()
     *
     * @throws DriverException
     */
    public function createCore(array $frames): CoreInterface
    {
        try {
            $core = new Core(new Imagick());
        } catch (ImagickException $e) {
            throw new DriverException('Failed to create new core', previous: $e);

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Cap allowed dimensions at the API boundary (e.g. <= 8192px per side or your business maximum)
  2. For legitimately huge canvases, raise memory_limit for the worker and check ImageMagick limits (`convert -list resource`)
  3. Read $e->getPrevious() for the native reason (memory vs policy vs coder)

Example fix

// before
$image = $manager->create($request->input('width'), $request->input('height'));

// after
$width = min(8192, max(1, (int) $request->input('width', 1000)));
$height = min(8192, max(1, (int) $request->input('height', 1000)));
$image = $manager->create($width, $height);
Defensive patterns

Strategy: validation

Validate before calling

const MAX_CANVAS = 8192;
if ($width < 1 || $height < 1 || $width > MAX_CANVAS || $height > MAX_CANVAS) {
    throw new InvalidArgumentException('Canvas size out of allowed range');
}
$image = $manager->create($width, $height);

Try / catch

try {
    $image = $manager->create($width, $height);
} catch (\Intervention\Image\Exceptions\DriverException $e) {
    $native = $e->getPrevious()?->getMessage() ?? 'unknown';
    throw new RuntimeException('Canvas allocation failed: ' . $native, 0, $e);
}

Prevention

When it happens

Trigger: $manager->create(30000, 30000)-scale canvases where the pixel buffer exceeds PHP memory_limit or ImageMagick's policy.xml resource caps; degraded ImageMagick installs rejecting newImage on certain builds.

Common situations: Dynamic banner/poster generation accepting user-supplied sizes without caps; effectively-DoS inputs reaching the canvas API.

Related errors


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