Skip to content
Home » News » How to Fix “libpng warning: iCCP: known incorrect sRGB profile” in Magento 2

How to Fix “libpng warning: iCCP: known incorrect sRGB profile” in Magento 2

Have you encountered the “libpng warning: iCCP: known incorrect sRGB profile” message while working with images in Magento 2? This is a common problem when processing PNG images, especially when you resize them using Magento’s CLI commands.

This guide will explain what this warning means and provide easy ways to fix it specifically for Magento 2.

What Does “libpng warning” Mean?

Screenshot of "libpng warning: iCCP: known incorrect sRGB profile" warning in Magento 2

Libpng” is a tool that processes PNG images, and when a PNG file has a wrong color profile (iCCP chunk), this warning appears. You may read more about iCCP chunk here.

Why Does This Happen in Magento 2?

In Magento 2, the  “libpng warning: iCCP: known incorrect sRGB profile” error is shown because some images uploaded to Magento 2 contain incorrect color profiles. When Magento tries to process these images, it triggers a warning. Although it’s just a warning, still, it can lead to issues with image generation and performance. 

This warning can be especially frustrating when you’re working with multiple images in Magento 2. Below, we offer several solutions to the problem.

How to Solve “libpng warning: iCCP: known incorrect sRGB profile” issue in Magento 2

To get rid of this warning, one needs to fix the color profile in PNG images before Magento starts processing them. Here are some simple ways to do it.

Method 1: Use ImageMagick to Remove Incorrect Color Profiles

ImageMagick, which is supported by Magento 2, can fix this issue.

To fix one image, run this command inside your Magento root directory:

convert pub/media/catalog/product/original.png -strip pub/media/catalog/product/fixed.png

This will take YourOriginal.png, remove the wrong color profile, and save a clean version as YourFixed.png.

To fix all PNG product images at once and process multiple images in Magento’s pub/media directory, use this command:

find pub/media/catalog/product -type f -name '*.png' -exec mogrify -strip {} +

⚠️ Important notice: Always back up your images before running these commands.

Method 2: Use pngcrush to Remove Incorrect Color Profiles

Another tool that can be used for optimizing PNG images and solving the libpng warning issue is pngcrush.

To fix one image, run the following command:

pngcrush -ow -rem allb -reduce pub/media/catalog/product/original.png

Where the -ow option overwrites the original image, and -rem allb removes the incorrect color profile.

To fix all PNG images in Magento 2 and clean up their color profile, run the following command: 

find pub/media/catalog/product -type f -name '*.png' -exec pngcrush -ow -rem allb -reduce {} \;

Method 3: Automate Fixing PNG Images in Magento 2

If you upload images to Magento 2 on a regular basis, you can make the cleanup process automated by adding an ImageMagick command already to your image upload process.

For example, you can add a script which will  remove incorrect profiles from newly uploaded images automatically:

#!/bin/bash 
find pub/media/catalog/product -type f -name '*.png' -exec mogrify -strip {} +

This script should be run periodically to keep images clean.

Conclusion

The “libpng warning: iCCP: known incorrect sRGB profile” warning in Magento 2 is caused by incorrect color profiles in PNG images. The best way to fix this issue is by removing the incorrect profiles before Magento starts to process the images.

Quick Summary of Fixes:

  1. Use ImageMagick (convert or mogrify) to remove the incorrect color profile.
  2. Use pngcrush to clean up images.
  3. Automate the process with a script to keep Magento images warning-free.

Author

Leave a Reply

Your email address will not be published. Required fields are marked *