Intervention/image · error · ModifierException

Failed to apply ' . self::class . ', unable to processs imag

Error message

Failed to apply ' . self::class . ', unable to processs image trimming

What it means

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.

Source

Thrown at src/Drivers/Imagick/Modifiers/TrimModifier.php:33

{
    /**
     * @throws NotSupportedException
     * @throws ModifierException
     */
    public function apply(ImageInterface $image): ImageInterface
    {
        if ($image->isAnimated()) {
            throw new NotSupportedException('Trim modifier cannot be applied to animated images');
        }

        $imagick = $image->core()->native();

        try {
            $result = $imagick->trimImage(($this->tolerance / 100 * $imagick->getQuantum()) / 1.5)
                && $imagick->setImagePage(0, 0, 0, 0);

            if ($result === false) {
                throw new ModifierException(
                    'Failed to apply ' . self::class . ', unable to processs image trimming',
                );
            }
        } catch (ImagickException $e) {
            throw new ModifierException(
                'Failed to apply ' . self::class . ', unable to processs image trimming',
                previous: $e,
            );
        }

        return $image;
    }
}

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Confirm the source image loads cleanly and re-apply trim on a fresh object
  2. Pre-convert unusual colorspaces/formats to a common one (e.g. sRGB PNG/JPEG) before trimming
  3. Inspect getPrevious() if the exception variant fired to distinguish wand errors from false returns
  4. Test the identical file through the imagick CLI to check whether trim works at the ImageMagick level

Example fix

// before
$image->trim(10); // trimImage() returned false

// after
$image = $manager->read($path); // fresh decode
try {
    $image->trim(10);
} catch (ModifierException $e) {
    $logger->warning('Trim failed, keeping untrimmed image: ' . $e->getMessage());
}
Defensive patterns

Strategy: try-catch

Try / catch

use Intervention\Image\Exceptions\ModifierException;

try {
    $image->trim($tolerance);
} catch (ModifierException $e) {
    $logger->info('Trim produced no result, keeping original: ' . $e->getMessage());
    // trimming is often optional - continue with the untrimmed image
}

Prevention

When it happens

Trigger: $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.

Common situations: 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.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/c7c57d7325a60bab. Report an issue: GitHub.