-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed a bug with channel 4 population in ImageQt #8507
Conversation
1. Fixed a bug with channel 4 population and format inconsistencies: lines 164, 167. 2. Added PyQt5 support. The changes have been tested.
Hi. We deliberately deprecated support for PyQt5 in Pillow 9.2.0 - https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#pyqt5-and-pyside2
Support was removed on schedule in Pillow 10. As for your 'bug with channel 4 population and format inconsistencies', when I attempt to show an RGB image in PyQt6 on my macOS machine, the result looks fine. import sys
from PIL import Image, ImageQt
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
label = QLabel()
with Image.open('Tests/images/hopper.png') as im:
assert im.mode == "RGB"
pixmap = ImageQt.toqpixmap(im)
label.setPixmap(pixmap)
self.setCentralWidget(label)
self.resize(im.width, im.height)
def button_clicked(self, s):
print("click", s)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec() Is it a problem that only happens with PyQt5? Could you provide a short code snippet to demonstrate? |
No, I have managed to reproduce this issue in both PyQt5 and PyQt6. The corrections I made to the code resolved the issue. Although PyQt5 was not necessary for the original problem, its support was straightforward to implement. I used it to replicate the issue repeatedly. from PyQt6.QtWidgets import QPushButton, QListWidget, QWidget, QApplication, QLabel, QVBoxLayout
from PyQt6.QtCore import Qt
#* The problem is also reproduced in the example using PyQt5.
# from PyQt5.QtWidgets import QPushButton, QListWidget, QWidget, QApplication, QLabel, QVBoxLayout
# from PyQt5.QtCore import Qt
from PIL import Image, ImageQt
def load_img():
# The problem only occurs with RGB images,
# as indicated in the changes that I suggested.
img = Image.open("cat.jpg")
# The RGB image causes the program to crash with no obvious error in the console,
# or it loads in an incorrect format (I have attached a screenshot).
pixmap = ImageQt.toqpixmap(img)
picture_view.setPixmap(pixmap)
app = QApplication([])
window = QWidget()
window.resize(700, 600)
btn = QPushButton('load image to pixmap')
picture_view = QLabel('Image View')
picture_view.setStyleSheet("background: magenta")
layout = QVBoxLayout(window)
layout.addWidget(btn)
layout.addWidget(picture_view)
btn.clicked.connect(load_img)
window.show()
app.exec() |
Could you provide a copy of cat.jpg? What operating system are you using? What version of PyQt6? >>> from PyQt6.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
>>> print("Qt: v", QT_VERSION_STR, "\tPyQt: v", PYQT_VERSION_STR)
Qt: v 6.7.1 PyQt: v 6.7.0 |
Qt: v 6.7.1 PyQt: v 6.7.1 Microsoft Windows [Version 10.0.17763.1697] I have tried to reproduce the error with other RGB images. In total, I have checked 4 images in the jpg format and there have been problems with all of them. However, there are no issues with the png format. The picture was downloaded from the Freepik website. |
I also tested Pillow versions 10.0.0 and 9.5.0. The error was discovered during classes with my student (also Windows). It appeared on his PC, I was able to reproduce it on mine. So, the issue has been present in multiple versions of Pillow and occurs on Windows machines. |
I put together a commit to try and replicate this on GitHub Actions - it is indeed a problem on Windows but not on macOS This PR does indeed fix the problem |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@codev8services you may have noticed that our test suite is failing here, because it doesn't expect RGB images to be turned into RGBA. I've come up with an alternative suggestion that lets us continue to use RGB. Would you mind testing #8509? |
#8509 has now been merged instead. |
Changes proposed in this pull request:
The changes have been tested.