libpng warning: iCCP: known incorrect sRGB profile

313,219

Solution 1

Libpng-1.6 is more stringent about checking ICC profiles than previous versions. You can ignore the warning. To get rid of it, remove the iCCP chunk from the PNG image.

Some applications treat warnings as errors; if you are using such an application you do have to remove the chunk. You can do that with any of a variety of PNG editors such as ImageMagick's

convert in.png out.png

To remove the invalid iCCP chunk from all of the PNG files in a folder (directory), you can use mogrify from ImageMagick:

mogrify *.png

This requires that your ImageMagick was built with libpng16. You can easily check it by running:

convert -list format | grep PNG

If you'd like to find out which files need to be fixed instead of blindly processing all of them, you can run

pngcrush -n -q *.png

where the -n means don't rewrite the files and -q means suppress most of the output except for warnings. Sorry, there's no option yet in pngcrush to suppress everything but the warnings.


Binary Releases of ImageMagick are here


For Android Projects (Android Studio) navigate into res folder.

For example:

C:\{your_project_folder}\app\src\main\res\drawable-hdpi\mogrify *.png

Solution 2

Use pngcrush to remove the incorrect sRGB profile from the png file:

pngcrush -ow -rem allb -reduce file.png
  • -ow will overwrite the input file
  • -rem allb will remove all ancillary chunks except tRNS and gAMA
  • -reduce does lossless color-type or bit-depth reduction

In the console output you should see Removed the sRGB chunk, and possibly more messages about chunk removals. You will end up with a smaller, optimized PNG file. As the command will overwrite the original file, make sure to create a backup or use version control.

Solution 3

Solution

The incorrect profile could be fixed by:

  1. Opening the image with the incorrect profile using QPixmap::load
  2. Saving the image back to the disk (already with the correct profile) using QPixmap::save

Note: This solution uses the Qt Library.

Example

Here is a minimal example I have written in C++ in order to demonstrate how to implement the proposed solution:

QPixmap pixmap;
pixmap.load("badProfileImage.png");
QFile file("goodProfileImage.png");
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "PNG");

The complete source code of a GUI application based on this example is available on GitHub.

UPDATE FROM 05.12.2019: The answer was and is still valid, however there was a bug in the GUI application I have shared on GitHub, causing the output image to be empty. I have just fixed it and apologise for the inconvenience!

Solution 4

You can also just fix this in photoshop...

  1. Open your .png file.
  2. File -> Save As and in the dialog that opens up uncheck "ICC Profile: sRGB IEC61966-2.1"
  3. Uncheck "As a Copy".
  4. Courageously save over your original .png.
  5. Move on with your life knowing that you've removed just that little bit of evil from the world.

Solution 5

To add to Glenn's great answer, here's what I did to find which files were faulty:

find . -name "*.png" -type f -print0 | xargs \
       -0 pngcrush_1_8_8_w64.exe -n -q > pngError.txt 2>&1

I used the find and xargs because pngcrush could not handle lots of arguments (which were returned by **/*.png). The -print0 and -0 is required to handle file names containing spaces.

Then search in the output for these lines: iCCP: Not recognizing known sRGB profile that has been edited.

./Installer/Images/installer_background.png:    
Total length of data found in critical chunks            =     11286  
pngcrush: iCCP: Not recognizing known sRGB profile that has been edited

And for each of those, run mogrify on it to fix them.

mogrify ./Installer/Images/installer_background.png

Doing this prevents having a commit changing every single png file in the repository when only a few have actually been modified. Plus it has the advantage to show exactly which files were faulty.

I tested this on Windows with a Cygwin console and a zsh shell. Thanks again to Glenn who put most of the above, I'm just adding an answer as it's usually easier to find than comments :)

Share:
313,219

Related videos on Youtube

Reza Karami
Author by

Reza Karami

Updated on July 08, 2022

Comments

  • Reza Karami
    Reza Karami 6 months

    I'm trying to load a PNG image using SDL but the program doesn't work and this error appears in the console

    libpng warning: iCCP: known incorrect sRGB profile

    Why does this warning appear? What should I do to solve this problem?

  • Maxito
    Maxito about 8 years
    With ImageMagick you can use the -strip command. Specifically, I used mogrify to affect all images in a folder. My command looked like this: mogrify -strip *.png
  • Glenn Randers-Pehrson
    Glenn Randers-Pehrson about 8 years
    The -strip option will remove all profiles. If you omit the -strip option (mogrify *.png), only incorrect profiles will be deleted.
  • Andy Brice
    Andy Brice almost 7 years
    That worked! Do do it recursively from the current folder put this in a .bat file : For /R %%i in (*.png) do PNGCRUSH.EXE -ow -rem allb -reduce %%i
  • friederbluemle
    friederbluemle almost 7 years
    And a one-liner for *nix to recursively fix all png files in the current directory: find . -type f -iname '*.png' -exec pngcrush -ow -rem allb -reduce {} \; (Tested on GNU/Linux)
  • Kyle Strand
    Kyle Strand over 6 years
    This is nicely cross-platform, though if you're on a platform that supports a nice *NIX-y shell such as Zsh or Bash, you can just use mogrify **/*.png.
  • Devan Williams
    Devan Williams over 6 years
    Yeah, good point. I only used Python because we develop on Windows and Linux and wanted to commit this script to our repo for future use.
  • Uflex about 6 years
    Is there a way of finding out which file is triggering the warning? Running mogrify **/*.png seems to modify all files in the tree. I would prefer updating only the one faulty image.
  • Quantuple
    Quantuple almost 6 years
    I am surprised that this answer did not get upvoted. It does not require installing anything and it works... what more could one ask for :)
  • iKlsR
    iKlsR almost 6 years
    Above line by frieder works inside git bash on windows as well.
  • guido
    guido over 5 years
    I didn't find pngfix in the standard OS El Capitan installation (or perhaps I didn't search well enough), but I found it in the MAMP installation which I had. Worked perfectly! Thanks! Upvoted
  • Adriel Jr
    Adriel Jr over 5 years
    You are right! I installed it with "brew install libpng" a long time ago.
  • kfunk over 5 years
    This deserves more upvotes. All the other solutions touch every file, which is especially bad if you have lots of images in a version-control system. Thanks for the script!
  • Mitch
    Mitch almost 5 years
    I got "n!ew ERR 08 read Undefined_error:_0 Undefined_error:_0 not_a_PNG_(too_short) car.png" when running this on 10.13.2.
  • val is still with Monica
    val is still with Monica over 4 years
    Use find . -type f -name '*.png' -execute mogrify \{\} \; to recursively modify .png files in current directory.
  • Adriel Jr
    Adriel Jr over 4 years
    @Mitch Still runs ok after upgrading to 10.13.6.
  • pbhj
    pbhj over 4 years
    I have pngcrush 1.7.85, uses libpng 1.6.21 and zlib 1.2.8 but my pngcrush doesn't have -warn nor -reduce flags so this solution doesn't work.
  • Gabriel Devillers
    Gabriel Devillers about 4 years
    On Debian, to find the files that were problematic in my software, I used find . -name "*.png" -exec sh -c 'echo Testing {} && pngcrush -n -q {}' \; Every erroneous PNG will generate pngcrush: iCCP: known incorrect sRGB profile
  • Pysis
    Pysis over 3 years
    Had the ImageMagick binaries freeze my computer, maybe from working too hard, and after leaving overnight, had to restart forcefully. Used the pngcrush application to detect the issue as mentioned, -ow to overwrite and fix the file, and also reduced the size by about 1/6th! Just had to get the program's source code for my mac, compile, install manually, and run it. GitHub Kjuly/pngcrush might have a precompiled binary, but not sure. Sourceforge only seemed to have Windows exe's available and the source code. friederbluemle's answer seems to do this and more.
  • KeyC0de
    KeyC0de about 3 years
    Pngcrush doesn't remove this chunk in my case. But imagemagick's mogrify did it.
  • MH.AI.eAgLe
    MH.AI.eAgLe over 1 year
    I've tested your solution but I'm getting this error: find: ‘’: No such file or directory 0 errors fixed" please guide precisely how to address the image folder.
  • Lin GU over 1 year
    great, it works for me, thanks for sharing
  • Sunchock
    Sunchock over 1 year
    I did the trick with Photofiltre 7. Just open the image and then save as a new one over the orginal png. Works fine, thanks for the tip
  • Spencer
    Spencer over 1 year
    @Sunchock Nice. Somehow this is still my top rated answer 4 years later... Just a simple "Save".
  • Charles Duffy
    Charles Duffy 9 months
    You don't need to both use a raw string and double up backslashes -- only one or the other is required.