{"record":{"id":"7cb7ed31b923b519","repo":"Intervention/image","slug":"failed-to-apply-class-unable-to-pixelate-image","errorCode":null,"errorMessage":"Failed to apply {class}, unable to pixelate image","messagePattern":"Failed to apply (.+?), unable to pixelate image","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/PixelateModifier.php","lineNumber":46,"sourceCode":"\n    /**\n     * @throws ModifierException\n     */\n    protected function pixelateFrame(FrameInterface $frame): void\n    {\n        $size = $frame->size();\n\n        try {\n            $result = $frame->native()->scaleImage(\n                (int) round(max(1, $size->width() / $this->size)),\n                (int) round(max(1, $size->height() / $this->size)),\n            ) && $frame->native()->scaleImage(\n                $size->width(),\n                $size->height(),\n            );\n\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to pixelate image',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to pixelate image',\n                previous: $e,\n            );\n        } catch (DivisionByZeroError $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to pixelate image',\n                previous: $e,\n            );\n        }\n    }\n}\n","sourceCodeStart":28,"sourceCodeEnd":63,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/PixelateModifier.php#L28-L63","documentation":"pixelate() downscales each frame to roughly width/size and height/size (clamped to a 1-pixel minimum) and then scales it back up, producing blocky pixels. This exception fires when either of the two chained scaleImage() calls returns false, making the combined && expression false. The pixelation size itself is already validated (constructor rejects values < 1), so the failure comes from the native scaling step.","triggerScenarios":"$image->pixelate($size) where a scaleImage() stage returns false: downscaling to 1px then upscaling a very large frame trips resource/policy ceilings, or the frame data is unreadable.","commonSituations":"Generating pixelated previews of multi-megapixel photos on memory-constrained workers; hosts whose policy.xml caps width/height so the upscale-back stage is denied; pixelating frames of long GIF animations frame by frame.","solutions":["Inspect $e->getPrevious()?->getMessage() for the native reason (usually resource or policy wording)","Raise memory_limit or the policy.xml width/height/area limits so both scale stages can allocate","Pixelate a pre-downscaled copy and composite it back instead of pixelating the full-resolution frame","Reduce the pixelation size (larger blocks need the same allocations but a smaller intermediate) or process one frame at a time"],"exampleFix":"// before\n$image->pixelate(20); // full-res frame, both scale stages unguarded\n\n// after\nuse Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->pixelate(20);\n} catch (ModifierException $e) {\n    $image->resize(1200, null)->pixelate(20); // fall back to smaller working size\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->pixelate(20);\n} catch (ModifierException $e) {\n    $image->resize(1200, null)->pixelate(20); // degrade to smaller working size\n}","preventionTips":["Pixelate the display-sized image, not the original; the upscale-back stage allocates the full frame again","Check ImageMagick width/height policy before promising pixelated full-res previews","For animations, pixelate one extracted frame instead of every frame when performance matters"],"tags":["php","imagick","intervention-image","pixelate","scaleimage","memory-limit"],"backgroundTag":"image-pixelation-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}