Quick answer: The warning comes from libpng, the C library that decodes PNG files for pygame.image.load(). One of your PNGs has an embedded ICC colour profile that libpng recognises as outdated or malformed. The image still loads and looks the same. To remove the message, strip the profile from the file: magick mogrify -strip *.png, optipng -strip all *.png, or re-save it with Pillow without the icc_profile.
Your game runs, the sprites draw, and the console fills with the same line once for every image it loads. Nothing is broken, which is why this warning gets ignored for months, until a real traceback scrolls past unnoticed among two hundred copies of it. The message never names a file, and Python’s warning filters have no effect on it. This guide covers what libpng is objecting to, how to list the PNGs that trigger it, three ways to strip the profile, and how to stop new art from bringing it back.
- The exact warning
- What causes it
- Why Python cannot silence it
- How to find the affected files
- Fix 1: strip the profile with a command-line tool
- Fix 2: strip the profile with Pillow
- Fix 3: stop embedding the profile at export
- Fix 4: check for it automatically
- When you cannot change the files
- The same warning outside Pygame
- How to confirm the fix
- What Bugnet sees and does not see here
- Related guides
- Frequently asked questions
The exact warning
libpng warning: iCCP: known incorrect sRGB profile
Related messages from the same check, with the same fix:
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: out-of-date sRGB profile with no signature
libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
libpng warning: iCCP: profile 'ICC Profile': 0h: PCS illuminant is not D50
libpng warning: iCCP: too many profiles
iCCP is the name of the PNG chunk that holds an embedded ICC colour profile. Pygame loads PNG files through SDL_image, and in most builds SDL_image decodes them with libpng. Since version 1.6, libpng inspects that chunk while reading the file and prints a line to standard error when it does not like what it finds. It is a warning: decoding continues, pygame.image.load() returns a normal Surface, and no exception is raised. You get one line per affected file per load.
What causes it
- The PNG embeds an old sRGB profile. libpng carries a list of sRGB profiles that were widely distributed with wrong data in them, and an image editor wrote one of those into the file on export. This is the common case by a wide margin, and it usually arrives with art exported from an older editor or with a purchased asset pack.
- The file has colour chunks that disagree. A PNG can describe its colour space three ways: an
iCCPprofile, ansRGBchunk, andcHRMchromaticity values. When a tool writes sRGB in one place and slightly different chromaticities in another, you get thecHRM chunk does not match sRGBvariant. - A tool edited or re-wrapped the profile. Batch converters and some optimisers copy a profile across and alter its header, which produces the
has been editedandPCS illuminant is not D50variants.
Your code is not involved in any of these. The same file prints the same warning in every program that reads it with libpng 1.6 or later. Whether you see it at all depends on how the SDL_image inside your pygame or pygame-ce wheel was built: a build that decodes PNG with a different library stays quiet. That explains a file that warns on one machine and not on another.
Why Python cannot silence it
The line is written by C code straight to the process’s standard error stream. It is not a Python Warning, so warnings.filterwarnings("ignore"), python -W ignore and reassigning sys.stderr all do nothing. Pygame has no setting for it either.
It is still worth fixing. A console that prints the same line for every sprite hides the one traceback that matters, and the warning ends up in every log a player sends you, where it looks like the cause of whatever they are reporting. Pygame never applied the profile in the first place (SDL_image hands you the raw pixel values), so removing it does not change how the game looks.
How to find the affected files
The warning does not include a file name. If you only have a handful of images, log each path to standard error before loading it, so the warning appears right under the file that caused it:
import sys
import pygame
def load_image(path):
print(f"loading {path}", file=sys.stderr, flush=True)
return pygame.image.load(path)
For a whole asset folder, scan the files instead. Pillow exposes the embedded profile as icc_profile in the image’s info dictionary, and the cHRM and sRGB chunks as chromaticity and srgb. Install it with pip install pillow and save this as find_png_profiles.py:
import sys
from pathlib import Path
from PIL import Image
root = Path(sys.argv[1] if len(sys.argv) > 1 else ".")
flagged = 0
for path in sorted(root.rglob("*.png")):
with Image.open(path) as im:
chunks = [key for key in ("icc_profile", "chromaticity", "srgb") if key in im.info]
if chunks:
flagged += 1
print(f"{path}: {', '.join(chunks)}")
print(f"{flagged} PNG file(s) carry colour profile data")
sys.exit(1 if flagged else 0)
Run python find_png_profiles.py assets. Every file it lists is a candidate. Not every embedded profile triggers the warning (a correct, current sRGB profile passes), but a game sprite has no use for any of them, so treat the whole list as the work to do. The script exits with status 1 when it finds something, which matters later.
With ImageMagick installed, magick identify -verbose sprite.png shows the same thing for one file: look for a Profiles: block containing a Profile-icc line. On ImageMagick 6 the command is identify without the magick prefix.
Fix 1: strip the profile with a command-line tool
All three tools below rewrite the file without its colour chunks. They overwrite in place, so commit or back up the folder first.
ImageMagick (use mogrify alone on version 6):
magick mogrify -strip assets/*.png
-strip removes profiles, comments and the iCCP, sRGB, cHRM and gAMA chunks. A shell wildcard does not descend into subfolders. On Linux and macOS, walk the tree with find:
find assets -name "*.png" -exec magick mogrify -strip {} +
In a Windows command prompt:
for /r assets %f in (*.png) do magick mogrify -strip "%f"
OptiPNG strips metadata and recompresses losslessly in one pass:
optipng -strip all assets/*.png
pngcrush, one file at a time:
pngcrush -ow -rem allb -reduce sprite.png
-ow overwrites the input, and -rem allb removes every ancillary chunk except transparency and gamma, which takes the profile with it.
Fix 2: strip the profile with Pillow
If your team already has Python and would prefer not to install another tool, do the same job with a script. Pillow writes the icc_profile it finds in info back into the saved file, so the script has to remove that key before saving. It leaves the transparency entry alone, which keeps palette images with a transparent colour intact.
import sys
from pathlib import Path
from PIL import Image
TRIGGERS = ("icc_profile", "chromaticity", "srgb")
root = Path(sys.argv[1] if len(sys.argv) > 1 else ".")
for path in sorted(root.rglob("*.png")):
with Image.open(path) as im:
if not any(key in im.info for key in TRIGGERS):
continue
clean = im.copy()
for key in TRIGGERS + ("gamma",):
clean.info.pop(key, None)
clean.save(path, optimize=True)
print(f"stripped {path}")
The copy is made inside the with block and saved after it closes, so the script never writes to a file it is still reading from. Pixel data, mode and size are unchanged. Text metadata the editor stored in the file is dropped, which is rarely a loss for a sprite.
Fix 3: stop embedding the profile at export
Stripping files fixes today’s assets. The next export from the same editor brings the profile back, so change the export settings as well. Most image editors have a checkbox in the PNG export or save dialog that controls whether the document’s colour profile is written into the file. In Photoshop it is labelled Embed Color Profile, in GIMP’s PNG export dialog it is Save color profile; other tools use similar wording, and the label moves between versions. Turn it off for game art and save that as the default or as an export preset.
One caution for art that was authored in a wide-gamut space such as Display P3 or Adobe RGB: convert the document to sRGB in the editor before exporting. Stripping a wide-gamut profile leaves pixel values that were meant for a different colour space, and although pygame draws them exactly as it did before, other tools will now show the file differently.
Fix 4: check for it automatically
Asset packs, contractors and a teammate’s fresh install will all reintroduce profiles. Because find_png_profiles.py exits non-zero when it finds one, it works as a gate. A Git pre-commit hook (.git/hooks/pre-commit, marked executable):
#!/bin/sh
python tools/find_png_profiles.py assets || {
echo "PNG colour profiles found. Run: python tools/strip_png_profiles.py assets"
exit 1
}
Hooks in .git/hooks are local to each clone, so run the same command in CI or in your build script too. If you already have an asset build step (packing atlases, converting audio), put the strip script there and the source files stop mattering.
When you cannot change the files
A game that loads player-made mods or downloaded images cannot clean them first. The only way to hide the warning then is to redirect the C-level standard error stream around the load call:
import contextlib
import os
import sys
@contextlib.contextmanager
def quiet_c_stderr():
sys.stderr.flush()
saved = os.dup(2)
devnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(devnull, 2)
try:
yield
finally:
os.dup2(saved, 2)
os.close(devnull)
os.close(saved)
Use it as with quiet_c_stderr(): surface = pygame.image.load(path). Keep the block that small: everything written to standard error inside it is discarded, including messages you would want. Python exceptions still propagate normally. This works on Linux and macOS; on Windows it depends on the C runtime the libpng build uses, so test it before relying on it.
The same warning outside Pygame
The message is libpng’s, so the same files produce it anywhere libpng 1.6 or later reads them: C and C++ games using SDL2_image, Qt and PyQt applications loading icons, OpenCV’s imread, and pdfLaTeX when it includes a PNG figure. The fix is identical everywhere, because the problem is in the file. If you landed here from one of those, the strip commands above apply unchanged.
How to confirm the fix
Run the finder again and check that it reports zero files. Then run the game with standard error captured and search the capture:
python main.py 2> stderr.txt
Visit every scene that loads art, quit, and search stderr.txt for libpng. Images loaded lazily (a boss sprite, an ending screen) only warn when you reach them, which is why the file scan is the more reliable of the two checks.
What Bugnet sees and does not see here
Bugnet does not report this warning, and should not. The Pygame SDK (pip install bugnet-sdk) installs an exception hook when you call bugnet_sdk.init(api_key); it files uncaught Python exceptions with the traceback, platform, OS version and game version. A libpng warning is text printed by C code and raises nothing, so there is nothing for the hook to catch.
The connection is indirect. Image loading does fail for real on players’ machines: a missing file, a path that only worked from your project folder, a format the build cannot decode. Those raise FileNotFoundError or pygame.error, and when nothing catches them they are filed, grouped by title so one broken asset is one entry with a count. A console free of libpng noise is what lets you notice the same failures locally first. Setup is in the getting started guide.
Related guides
- How to Fix “FileNotFoundError” for Images and Sounds in Pygame (Working Directory Problems)
- Fix: Pygame image.load Wrong Colors Without convert_alpha
- Fix: Pygame image.load Extension Error
- How to Fix “Failed to execute script due to unhandled exception” in a PyInstaller Pygame Build
- How to Set Up Crash Reporting in Pygame for Windows
Frequently asked questions
Is “libpng warning: iCCP: known incorrect sRGB profile” an error?
No. It is a warning printed by the libpng library while it decodes a PNG that contains an outdated embedded sRGB colour profile. The image loads normally and pygame.image.load returns a valid Surface. The only harm is console noise that can hide real errors.
How do I suppress the libpng iCCP warning in Pygame?
Remove the colour profile from the PNG files that cause it, for example with magick mogrify -strip or optipng -strip all. Python warning filters do not work because the message is written by C code directly to standard error, not raised as a Python warning.
How do I find which PNG file causes the libpng warning?
The warning does not name the file. Scan your asset folder with a short Pillow script that opens each PNG and checks whether icc_profile is present in the image info dictionary, or run ImageMagick identify -verbose on a file and look for a Profile-icc line.
Does stripping the ICC profile change how my sprites look?
Not in Pygame. SDL_image ignores the embedded profile and gives you the raw pixel values, so the game draws the image exactly as before. Colour-managed tools may show a wide-gamut image differently after stripping, so convert such art to sRGB before export.
Why does the warning appear on one computer and not another?
It depends on the PNG decoder inside the installed pygame build. Builds whose SDL_image uses libpng 1.6 or later print the warning, while builds that decode PNG with a different library do not. The file is the same in both cases, and stripping the profile fixes it everywhere.
The warning is about the file, not your code. Strip colour profiles from every PNG once, turn off profile embedding in your editor’s export dialog, and let a script fail the commit when one sneaks back in.