{"record":{"id":"3584c1300bcbfd78","repo":"Intervention/image","slug":"failed-to-create-new-image-3584c1","errorCode":null,"errorMessage":"Failed to create new image","messagePattern":"Failed to create new image","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Driver.php","lineNumber":73,"sourceCode":"     * @see DriverInterface::createImage()\n     *\n     * @throws InvalidArgumentException\n     * @throws DriverException\n     */\n    public function createImage(int $width, int $height): ImageInterface\n    {\n        if ($width < 1 || $height < 1) {\n            throw new InvalidArgumentException('Invalid image size. Must be int<1, max>');\n        }\n\n        try {\n            $background = new ImagickPixel('rgba(255, 255, 255, 0)');\n\n            $imagick = new Imagick();\n            $imagick->newImage($width, $height, $background, 'png');\n            $this->applyDefaultSettings($imagick);\n        } catch (ImagickException | ImagickPixelException $e) {\n            throw new DriverException('Failed to create new image', previous: $e);\n        }\n\n        return new Image($this, new Core($imagick));\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DriverInterface::createCore()\n     *\n     * @throws DriverException\n     */\n    public function createCore(array $frames): CoreInterface\n    {\n        try {\n            $core = new Core(new Imagick());\n        } catch (ImagickException $e) {\n            throw new DriverException('Failed to create new core', previous: $e);","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Driver.php#L55-L91","documentation":"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.","triggerScenarios":"$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.","commonSituations":"Dynamic banner/poster generation accepting user-supplied sizes without caps; effectively-DoS inputs reaching the canvas API.","solutions":["Cap allowed dimensions at the API boundary (e.g. <= 8192px per side or your business maximum)","For legitimately huge canvases, raise memory_limit for the worker and check ImageMagick limits (`convert -list resource`)","Read $e->getPrevious() for the native reason (memory vs policy vs coder)"],"exampleFix":"// before\n$image = $manager->create($request->input('width'), $request->input('height'));\n\n// after\n$width = min(8192, max(1, (int) $request->input('width', 1000)));\n$height = min(8192, max(1, (int) $request->input('height', 1000)));\n$image = $manager->create($width, $height);","handlingStrategy":"validation","validationCode":"const MAX_CANVAS = 8192;\nif ($width < 1 || $height < 1 || $width > MAX_CANVAS || $height > MAX_CANVAS) {\n    throw new InvalidArgumentException('Canvas size out of allowed range');\n}\n$image = $manager->create($width, $height);","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->create($width, $height);\n} catch (\\Intervention\\Image\\Exceptions\\DriverException $e) {\n    $native = $e->getPrevious()?->getMessage() ?? 'unknown';\n    throw new RuntimeException('Canvas allocation failed: ' . $native, 0, $e);\n}","preventionTips":["Enforce a maximum canvas size at the API boundary","Run large-canvas jobs in workers with raised memory_limit and checked ImageMagick resource caps"],"tags":["imagick","memory","canvas","create","resource-limits"],"backgroundTag":"image-create-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}