{"record":{"id":"80983ff8428030f8","repo":"Intervention/image","slug":"failed-to-apply-intervention-image-drivers-imagick-80983f","errorCode":null,"errorMessage":"Failed to apply Intervention\\Image\\Drivers\\Imagick\\Modifiers\\ContainModifier, unable to resize image","messagePattern":"Failed to apply Intervention\\\\Image\\\\Drivers\\\\Imagick\\\\Modifiers\\\\ContainModifier, unable to resize image","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/ContainModifier.php","lineNumber":61,"sourceCode":"            if ($resize->height() > $crop->height()) {\n                $this->fillVerticalAreas($frame->native(), $crop, $resize, $background);\n            }\n        }\n\n        return $image;\n    }\n\n    /**\n     * Scale a native Imagick frame to the given dimensions\n     *\n     * @throws ModifierException\n     */\n    private function scaleFrame(mixed $native, int $width, int $height): void\n    {\n        try {\n            $result = $native->scaleImage($width, $height);\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to resize image',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to resize image',\n                previous: $e,\n            );\n        }\n    }\n\n    /**\n     * Set the background and image background color of a frame to transparent.\n     *\n     * @throws ModifierException\n     */\n    private function setFrameBackgroundTransparent(Imagick $native): void\n    {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/ContainModifier.php#L43-L79","documentation":"Thrown by ContainModifier::scaleFrame() when Imagick::scaleImage() returns false while fitting a frame inside the target box during $image->contain($w, $h). The contain pipeline scales each frame to the crop size before extending the canvas, so a false-returning scale aborts the operation. No previous exception is attached on this path.","triggerScenarios":"Calling $image->contain() where scaleImage cannot execute: target dimensions exceeding ImageMagick limits for the pixel cache, degraded wand state, or unsupported image mode. Since contain computes dimensions itself, bad user dimensions rarely reach here directly — it is an environment/wand failure.","commonSituations":"Contain on very large source images (panoramas, print scans) against tight policy.xml area/memory caps; processing after earlier operations destabilized the wand; shared hosts with low ImageMagick limits.","solutions":["Raise ImageMagick resource limits (policy.xml or Imagick::setResourceLimit for AREA/MEMORY) sized to your largest expected image.","Pre-downscale oversized sources before contain if full resolution is not required.","Confirm reproducibility via CLI (convert big.png -scale 800x600 out.png) to separate environment issues from code.","Re-read the image fresh from source if the wand may be stale from a prior failed modifier."],"exampleFix":"// before\n$image->contain(1200, 900); // scaleImage returns false on resource-capped host\n\n// after\n\\Imagick::setResourceLimit(\\Imagick::RESOURCETYPE_AREA, 512 * 1024 * 1024);\n\\Imagick::setResourceLimit(\\Imagick::RESOURCETYPE_MEMORY, 512 * 1024 * 1024);\n$image->contain(1200, 900);","handlingStrategy":"fallback","validationCode":"// guard against resource-capped environments before large contains\n$needed = $image->width() * $image->height();\n$areaCap = \\Imagick::getResourceLimit(\\Imagick::RESOURCETYPE_AREA);\nif ($areaCap > 0 && $needed > $areaCap) {\n    \\Imagick::setResourceLimit(\\Imagick::RESOURCETYPE_AREA, $needed * 4);\n}","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\ntry {\n    $image->contain(1200, 900);\n} catch (ModifierException $e) {\n    // fallback: pre-downscale then contain again\n    $image = $manager->read($source)->scaleDown(2000, 2000)->contain(1200, 900);\n}","preventionTips":["Set RESOURCETYPE_AREA/MEMORY limits appropriate to your largest input at bootstrap.","Downscale oversized uploads at ingest time; contain then works within modest limits."],"tags":["imagick","contain","resize","modifier-exception","resources"],"backgroundTag":"image-resize-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}