I’m using latest PyQt5
5.12.2 and I’m getting a weird message for every JPG picture that I’m showing in my script using QPixmap or QIcon.
qt.gui.icc: fromIccProfile: failed minimal tag size sanity
It isn’t causing anything and the script works as it should. The problem is that I’m trying to display a huge amount of jpg pictures at the same time (as a photo gallery) so the window gets unresponsive until all messages are printed for each photo.
I tried for hours to find something useful online but unfortunately, it seems like nearly no one had the same issue. I’m using some PNG files too and they don’t raise this error so I’m assuming that the problem is with jpg format. I tried using older pyqt5 versions but the only difference is that they are not printing the message but the problem remains.
Meanwhile, I tried to use this command to mute those messages since there is no use of them but the problem with unresponsive window for a few seconds remains even when it’s not printing in the console.
def handler(*args): pass qInstallMessageHandler(handler)
EDIT: I tried converting these images to PNG but the error remains. So the JPG format wasn’t the problem
I dug more deeply into ICC profiles and colour spaces and it seems like the colour space that your pictures are using is somehow non-standard for PyQt.
My solution is to convert these pictures to an ICC profile that is classical such as sRGB. Here’s an example function:
import io from PIL import Image, ImageCms def convert_to_srgb(file_path): '''Convert PIL image to sRGB color space (if possible)''' img = Image.open(file_path) icc = img.info.get('icc_profile', '') if icc: io_handle = io.BytesIO(icc) # virtual file src_profile = ImageCms.ImageCmsProfile(io_handle) dst_profile = ImageCms.createProfile('sRGB') img_conv = ImageCms.profileToProfile(img, src_profile, dst_profile) icc_conv = img_conv.info.get('icc_profile','') if icc != icc_conv: # ICC profile was changed -> save converted file img_conv.save(file_path, format = 'JPEG', quality = 50, icc_profile = icc_conv)
Using PIL library is a fast and effective way how to properly resolve that error.