Describe the bug
When attempting to capture an image and save it as a JPEG, an AttributeError is thrown because the code tries to set the mode attribute of a PIL Image object directly to 'RGBX'.
To Reproduce
Steps to reproduce the behavior:
Configure the camera to capture an image.
Call picam2.capture_file(image_path) to capture the image.
The error occurs when the save method in the CompletedRequest class tries to change the image mode.
Expected behavior
The image should be saved without any errors.
Actual behavior
The following error is raised:
AttributeError: can't set attribute
This occurs in the save method of CompletedRequest when handling a PIL Image object.
Code snippet:
if format_str in ('jpg', 'jpeg'):
if img.mode == "RGBA":
Nasty hack. Qt doesn't understand RGBX so we have to use RGBA. But saving a JPEG
# doesn't like RGBA so we have to bodge that to RGBX.
img.mode = "RGBX"
Proposed solution or workaround
A potential workaround could be creating a new image with the 'RGBX' mode instead of setting the mode on the existing object. However, this should be properly fixed in the library.
Environment:
Pi: Raspberry Pi 4B
OS: Raspberry Pi
Python version: 3.9.2
Camera model: Raspberry Pi Camera v3
Hi, thanks for reporting this. So far as I know, this is a change in PIL version 10, and the next release of Picamera2 will fix it. Might you be able to test whether this change works for you?
Describe the bug When attempting to capture an image and save it as a JPEG, an AttributeError is thrown because the code tries to set the mode attribute of a PIL Image object directly to 'RGBX'.
To Reproduce Steps to reproduce the behavior:
Configure the camera to capture an image. Call picam2.capture_file(image_path) to capture the image. The error occurs when the save method in the CompletedRequest class tries to change the image mode. Expected behavior The image should be saved without any errors.
Actual behavior The following error is raised: AttributeError: can't set attribute
This occurs in the save method of CompletedRequest when handling a PIL Image object.
Code snippet: if format_str in ('jpg', 'jpeg'): if img.mode == "RGBA":
Nasty hack. Qt doesn't understand RGBX so we have to use RGBA. But saving a JPEG
Proposed solution or workaround A potential workaround could be creating a new image with the 'RGBX' mode instead of setting the mode on the existing object. However, this should be properly fixed in the library.
Environment: Pi: Raspberry Pi 4B OS: Raspberry Pi Python version: 3.9.2 Camera model: Raspberry Pi Camera v3