{"record":{"id":"6446b16f4b2ea953","repo":"Intervention/image","slug":"invalid-image-size-must-be-int-1-max-6446b1","errorCode":null,"errorMessage":"Invalid image size. Must be int<1, max>","messagePattern":"Invalid image size\\. Must be int<1, max>","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Driver.php","lineNumber":63,"sourceCode":"        if (!extension_loaded('imagick') || !class_exists('Imagick')) {\n            throw new MissingDependencyException(\n                'Imagick PHP extension must be installed to use this driver',\n            );\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @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     *","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Driver.php#L45-L81","documentation":"Driver::createImage() rejects zero or negative width/height before touching ImageMagick. Reached through ImageManager::create($width, $height) (or APIs that build blank canvases). Typical cause: dimensions computed at runtime - e.g. a percentage of another image's size - rounding down to 0.","triggerScenarios":"$manager->create(0, 100); computed sizes like (int) round($source->width() * 0.05) collapsing to 0 for tiny sources; unvalidated user input where (int) 'abc' becomes 0.","commonSituations":"Thumbnail/resize-to-fit math operating on already-small images; form fields for canvas size missing validation; float-to-int casts of fractions below 1.","solutions":["Clamp before calling: max(1, (int) $width) / max(1, (int) $height)","Fix the upstream computation - check the aspect-ratio source for zero dimensions before deriving sizes","Validate/normalize user-supplied sizes (filter_var with FILTER_VALIDATE_INT, options min_range 1)"],"exampleFix":"// before\n$width = (int) round($source->width() * $ratio); // 0 for tiny sources\n$image = $manager->create($width, $height);\n\n// after\n$width = max(1, (int) round($source->width() * $ratio));\n$image = $manager->create($width, $height);","handlingStrategy":"validation","validationCode":"$width = max(1, (int) $width);\n$height = max(1, (int) $height);\n$image = $manager->create($width, $height);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp computed dimensions with max(1, ...) wherever ratios shrink sources","Validate user-supplied sizes with FILTER_VALIDATE_INT and min_range 1","Unit-test resize math against zero-dimension edge inputs"],"tags":["validation","dimensions","create","invalid-argument"],"backgroundTag":"invalid-image-dimensions","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}