Skip to content
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

Saving an image with JPEG2000 format doesn't accept Path object #5632

Closed
j-tai opened this issue Jul 24, 2021 · 1 comment · Fixed by #5633
Closed

Saving an image with JPEG2000 format doesn't accept Path object #5632

j-tai opened this issue Jul 24, 2021 · 1 comment · Fixed by #5633
Labels
Bug Any unexpected behavior, until confirmed feature.

Comments

@j-tai
Copy link

j-tai commented Jul 24, 2021

What did you do?

Save a JPEG 2000 image using a Path argument:

from pathlib import Path
from PIL import Image

img = Image.new('RGBA', (5, 5), '#00000000')
img.save(Path('image.jp2'), format='JPEG2000')

What did you expect to happen?

It should save the file correctly, since the documentation says that passing in a Path object is allowed.

What actually happened?

Traceback (most recent call last):
  File "/home/jtai/Desktop/pillow-fail/fail.py", line 5, in <module>
    img.save(Path('image.jp2'), format='JPEG2000')
  File "/home/jtai/Desktop/pillow-fail/venv/lib/python3.9/site-packages/PIL/Image.py", line 2235, in save
    save_handler(self, fp, filename)
  File "/home/jtai/Desktop/pillow-fail/venv/lib/python3.9/site-packages/PIL/Jpeg2KImagePlugin.py", line 247, in _save
    if filename.endswith(".j2k"):
AttributeError: 'PosixPath' object has no attribute 'endswith'

What are your OS, Python and Pillow versions?

  • OS: Pop!_OS 21.04
  • Python: 3.9.5
  • Pillow: 8.3.1
@radarhere radarhere added the Bug Any unexpected behavior, until confirmed feature. label Jul 24, 2021
@radarhere
Copy link
Member

You're right. I've created PR #5633 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants