plone / plone.scale

Contains image scaling logic for use in Zope environments. It supports Zope 2, Pyramid and other systems build on using the Zope ToolKit (ZTK).
https://pypi.org/project/plone.scale
2 stars 16 forks source link

Incompatible with Pillow 10.1+ #89

Closed mauritsvanrees closed 9 months ago

mauritsvanrees commented 9 months ago

Plone 6 uses Pillow 9.5. In 10.1.0 an incompatible change was made that causes an error in the tests:

Error in test testAlphaForcesPNG (plone.scale.tests.test_scale.ScalingTests.testAlphaForcesPNG)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.12.1/lib/python3.12/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.12.1/lib/python3.12/unittest/case.py", line 636, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.12.1/lib/python3.12/unittest/case.py", line 589, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/community/plone-coredev/6.1/src/plone.scale/plone/scale/tests/test_scale.py", line 63, in testAlphaForcesPNG
    self.assertEqual(scaleImage(result, 84, 103, "contain")[1], "JPEG")
  File "/Users/maurits/community/plone-coredev/6.1/src/plone.scale/plone/scale/scale.py", line 118, in scaleImage
    image, format_ = scaleSingleFrame(
  File "/Users/maurits/community/plone-coredev/6.1/src/plone.scale/plone/scale/scale.py", line 177, in scaleSingleFrame
    image.mode = "RGB"
AttributeError: property 'mode' of 'Image' object has no setter

This is when handling a JPEG image in RGBA mode where the "A" part (Alpha) is not really uses, to we convert it to RGB mode.

Apparently we should use image = image.convert("RGB") now. The tests then pass with both Pillow 9 and 10. I will create a PR.