How to resolve these libpng errors in pygame?

These errors are shown when I close the Game:

Libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB

These errors happen because I am using this:

pygame.display.set_icon(pygame.image.load("imagens/truco.png"))

How to solve this?

Author: Matheus Silva Pinto, 2017-11-04

2 answers

This not are errors, they are "warnings" (warning) and the problem may be in the image that is with the "color profile" (ICC profile) of the image and probably does not affect your application, you can even ignore these warnings if you wish, ie it is not a problem in your code.

What you can perhaps easily solve by using a drawing program to fix "the image" with problem, such as GIMP or Photoshop.

There is a online solution like this: http://tinypng.com - that in addition to probably solving these "warnings" will still reduce the size of the images making your program lighter in different senses.

There is also https://pmt.sourceforge.io/pngcrush / (download https://sourceforge.net/projects/pmt/files/pngcrush-executables / ) which is able to remove invalid color profiles, after installed using this command:

pngcrush -ow -rem allb -reduce file.png
 5
Author: Guilherme Nascimento, 2017-11-04 14:39:09

This is a warning issued by libpng. It means that the PNG image file you are using has iCCP chunks invalid .

To remove the invalid chunks from an image PNG, you can use the utility convert from the library ImageMagick passing the argument -strip on the command line:

$ convert icone.png -strip icone_ok.png

Assuming you have an image file, in the format PNG, with dimensions from 400x400, called icone.png:

SOpt

Follows a program capable of loading the image above by means of the function pygame.image.load() and then using it as the window icon created by means of the function pygame.display.set_icon() without any error or warning :

import sys
import pygame

pygame.init()

icon = pygame.image.load('icone.png')
screen = pygame.display.set_mode((500, 500))

pygame.display.set_caption('FooBar')
pygame.display.set_icon(icon)
screen.blit( icon, (50,50))

clk = pygame.time.Clock()
running = True;

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False;
    pygame.display.update()
    clk.tick(25);

pygame.quit()
sys.exit()

Example being tested on a Desktop Linux/GNOME:

insert the description of the image here

 3
Author: Lacobus, 2017-11-04 15:33:09