{"record":{"id":"c7c57d7325a60bab","repo":"Intervention/image","slug":"failed-to-apply-self-class-unable-to-pro","errorCode":null,"errorMessage":"Failed to apply ' . self::class . ', unable to processs image trimming","messagePattern":"Failed to apply ' \\. self::class \\. ', unable to processs image trimming","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/TrimModifier.php","lineNumber":33,"sourceCode":"{\n    /**\n     * @throws NotSupportedException\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        if ($image->isAnimated()) {\n            throw new NotSupportedException('Trim modifier cannot be applied to animated images');\n        }\n\n        $imagick = $image->core()->native();\n\n        try {\n            $result = $imagick->trimImage(($this->tolerance / 100 * $imagick->getQuantum()) / 1.5)\n                && $imagick->setImagePage(0, 0, 0, 0);\n\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to processs image trimming',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to processs image trimming',\n                previous: $e,\n            );\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":47,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/TrimModifier.php#L15-L47","documentation":"ModifierException from the Imagick TrimModifier: trimImage() plus the mandatory setImagePage(0, 0, 0, 0) canvas reset returned false, so the trim did not take effect. The tolerance is normalized against the image's quantum range ((tolerance/100 * quantum) / 1.5), so any tolerance value is valid - a false result points to the image state, not the tolerance. Note the message contains a verbatim triple-s typo ('processs'), so exact-string matching must copy it as-is.","triggerScenarios":"$image->trim($tolerance) on a static image when trimImage() or the chained setImagePage() returns false: image with no distinguishable border, invalid wand state, or an ImageMagick build refusing the operation for the format.","commonSituations":"Trimming images whose border color is not uniform (so trimImage() finds nothing and some builds return false); reusing image objects after earlier failures; CMYK or exotic-format sources.","solutions":["Confirm the source image loads cleanly and re-apply trim on a fresh object","Pre-convert unusual colorspaces/formats to a common one (e.g. sRGB PNG/JPEG) before trimming","Inspect getPrevious() if the exception variant fired to distinguish wand errors from false returns","Test the identical file through the imagick CLI to check whether trim works at the ImageMagick level"],"exampleFix":"// before\n$image->trim(10); // trimImage() returned false\n\n// after\n$image = $manager->read($path); // fresh decode\ntry {\n    $image->trim(10);\n} catch (ModifierException $e) {\n    $logger->warning('Trim failed, keeping untrimmed image: ' . $e->getMessage());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->trim($tolerance);\n} catch (ModifierException $e) {\n    $logger->info('Trim produced no result, keeping original: ' . $e->getMessage());\n    // trimming is often optional - continue with the untrimmed image\n}","preventionTips":["Treat trim as optional in pipelines and tolerate its failure","Feed trim well-formed images: re-decode from source when in doubt","Note the message contains 'processs' (three s) - account for it in string matching"],"tags":["imagick","trim","modifier","image-processing"],"backgroundTag":"imagick-operation-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}