{"record":{"id":"2895b0f617c560aa","repo":"Intervention/image","slug":"failed-to-apply-intervention-image-drivers-gd-modi-2895b0","errorCode":null,"errorMessage":"Failed to apply Intervention\\Image\\Drivers\\Gd\\Modifiers\\PixelateModifier, unable to process pixelation effect","messagePattern":"Failed to apply Intervention\\\\Image\\\\Drivers\\\\Gd\\\\Modifiers\\\\PixelateModifier, unable to process pixelation effect","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Modifiers/PixelateModifier.php","lineNumber":26,"sourceCode":"use Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\nuse Intervention\\Image\\Modifiers\\PixelateModifier as GenericPixelateModifier;\n\nclass PixelateModifier extends GenericPixelateModifier implements SpecializedInterface\n{\n    /**\n     * {@inheritdoc}\n     *\n     * @see ModifierInterface::apply()\n     *\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        foreach ($image as $frame) {\n            $result = imagefilter($frame->native(), IMG_FILTER_PIXELATE, $this->size, true);\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to process pixelation effect',\n                );\n            }\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":35,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Modifiers/PixelateModifier.php#L8-L35","documentation":"The GD driver applies pixelation with imagefilter($gd, IMG_FILTER_PIXELATE, $size, true) per frame and throws ModifierException when the call returns false. The block size is passed straight to GD and is not what fails here; a false return means GD could not run the filter on the native image - an invalid/destroyed GdImage or a frame in a state GD refuses to filter (e.g. palette frames produced outside the normal decode path).","triggerScenarios":"$image->pixelate($size) on frames whose native was replaced or invalidated by custom code; filtering palette-based frames from hand-built cores; the library's test suite forcing imagefilter() to fail (testApplyThrowsWhenSpecializedWithoutOverride).","commonSituations":"Raw GD interop layers; long-running workers where underlying resources were freed; test doubles exercising the failure branch.","solutions":["Re-decode the image from source and apply pixelate() on the fresh instance","Audit custom setNative()/imagedestroy() usage that corrupts frame state","Convert palette frames back to truecolor: foreach ($image as $frame) { imagepalettetotruecolor($frame->native()); }","Catch ModifierException and skip the effect"],"exampleFix":"// before: pixelate on possibly corrupted native frames\n$image->pixelate(10);\n\n// after: decode fresh and normalize before filtering\n$image = $manager->decode($sourceBinary);\nforeach ($image as $frame) {\n    if (!imageistruecolor($frame->native())) {\n        imagepalettetotruecolor($frame->native());\n    }\n}\n$image->pixelate(10);","handlingStrategy":"try-catch","validationCode":"foreach ($image as $frame) {\n    $native = $frame->native();\n    if (!$native instanceof GdImage || imagesx($native) < 1) {\n        throw new RuntimeException('Frame native is not a usable GdImage');\n    }\n    if (!imageistruecolor($native)) {\n        imagepalettetotruecolor($native);\n    }\n}\n\n$image->pixelate(10);","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->pixelate(10);\n} catch (ModifierException $e) {\n    $logger?->warning('Pixelate filter failed: ' . $e->getMessage());\n}","preventionTips":["Keep native frames untouched between modifier calls.","Normalize palette frames to truecolor before GD filters.","Verify GD builds on deployment targets with gd_info()."],"tags":["gd","pixelate","imagefilter","filter-failure","native-resource"],"backgroundTag":"gd-imagefilter-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}