Intervention/image · error · Intervention\Image\Exceptions\ModifierException

Failed to apply {class}, unable to preserve icc profiles

Error message

Failed to apply {class}, unable to preserve icc profiles

What it means

First failure step of the Imagick StripMetaModifier: Imagick::getImageProfiles('icc') threw while reading the embedded ICC profile so it can be re-applied after stripping. The Imagick encoders run this modifier automatically when strip: true is set (Jpeg, Webp, Avif, Heic, Tiff, Jxl, Jpeg2000), so it usually surfaces during encoding rather than from explicit metadata stripping.

Source

Thrown at src/Drivers/Imagick/Modifiers/StripMetaModifier.php:29

use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Interfaces\SpecializedInterface;

class StripMetaModifier implements ModifierInterface, SpecializedInterface
{
    /**
     * {@inheritdoc}
     *
     * @see Intervention\Image\Interfaces\ModifierInterface::apply()
     *
     * @throws ModifierException
     */
    public function apply(ImageInterface $image): ImageInterface
    {
        // preserve icc profiles
        try {
            $profiles = $image->core()->native()->getImageProfiles('icc');
        } catch (ImagickException $e) {
            throw new ModifierException(
                'Failed to apply ' . self::class . ', unable to preserve icc profiles',
                previous: $e,
            );
        }

        // remove meta data
        try {
            $result = $image->core()->native()->stripImage();
            if ($result === false) {
                throw new ModifierException(
                    'Failed to apply ' . self::class . ', unable to strip meta data',
                );
            }
        } catch (ImagickException $e) {
            throw new ModifierException(
                'Failed to apply ' . self::class . ', unable to strip meta data',
                previous: $e,
            );

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Read getPrevious() for the underlying ImagickException message to confirm the profile read is the failing step
  2. Try encoding without strip: true - if that works, the source profile blob is the problem
  3. Pre-clean or re-save the offending image externally (exiftool/mogrify) before upload
  4. Verify ImageMagick was built with LCMS delegate support (convert -list delegate | grep -i lcms)

Example fix

// before
$encoded = $image->encode(new WebpEncoder(quality: 85, strip: true));

// after
try {
    $encoded = $image->encode(new WebpEncoder(quality: 85, strip: true));
} catch (ModifierException $e) {
    $reason = $e->getPrevious()?->getMessage() ?? $e->getMessage();
    $logger->warning('Strip failed, encoding with metadata: ' . $reason);
    $encoded = $image->encode(new WebpEncoder(quality: 85));
}
Defensive patterns

Strategy: try-catch

Try / catch

use Intervention\Image\Exceptions\ModifierException;

try {
    $encoded = $image->encode(new WebpEncoder(quality: 85, strip: true));
} catch (ModifierException $e) {
    $reason = $e->getPrevious()?->getMessage() ?? $e->getMessage();
    $logger->warning('Strip/ICC step failed: ' . $reason);
    $encoded = $image->encode(new WebpEncoder(quality: 85)); // metadata kept
}

Prevention

When it happens

Trigger: $image->encode(new WebpEncoder(quality: 85, strip: true)) (or any Imagick encoder with strip: true, or modify(new StripMetaModifier())) when getImageProfiles('icc') throws - malformed/partial ICC blob in the source, corrupted image state, or an ImageMagick build without working profile support.

Common situations: Enabling strip on untrusted user uploads; images with broken embedded ICC profiles; ImageMagick installations compiled without the LCMS delegate; batch jobs where one poisoned file fails the encode step.

Related errors


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