PyQt5 - fromIccProfile: failed minimal tag size sanity error

May 2024 ยท 3 minute read

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

3 Answers

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.

UPDATED (Bit more polished code)

import io from PIL import Image, ImageCms def convert_to_srgb(file_path): """ Convert PIL image to sRGB color space (if possible) and save the converted file. """ img = Image.open(file_path) icc = img.info.get('icc_profile', '') icc_conv = '' 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.

I am making a GUI Image Viewer with Pyside2 and was having a similar issue. The images were loading fine and for my case there was no performances issues, but I keep getting these ICC warnings. And I didn't want to fix the original files, because my app is supposed to be only a viewer.

I don't know it will help for your case, but my solution is to first load the image with pillow ImageQT module

from pathlib import Path from PIL.ImageQt import ImageQt def load_image(path): if Path(path).is_file(): return ImageQt(path) 

Then in my QT Widget class that display the image, I load this image on a empty QPixmap:

def on_change(self, path): pixmap = QtGui.QPixmap() image = load_image(path) if image: pixmap.convertFromImage(image) if pixmap.isNull(): self.display_area_label.setText('No Image') else: self.display_area_label.setPixmap(pixmap) 

Just set the Qt.IgnoreAspectRatio flag and you won't get any more warnings.

from PyQt5.QtGui import QPixmap, QImage, Qt image = QImage("my_image.png") pixmap = QPixmap.fromImage(image, Qt.IgnoreAspectRatio) 

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobW5sZmiFdYSOqbCqrGVis7O7zKKanKiipLOquMRmnZqhnJqxbrnIp6CmmZxiwaKzjKygs51dqK6vtdOyZJ6qoqS%2F