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

Can't convert images with height / width < 64 to jpeg2000 #3161

Closed
bagipriyank opened this issue Jun 8, 2018 · 12 comments · Fixed by #5540
Closed

Can't convert images with height / width < 64 to jpeg2000 #3161

bagipriyank opened this issue Jun 8, 2018 · 12 comments · Fixed by #5540
Labels
Projects

Comments

@bagipriyank
Copy link

bagipriyank commented Jun 8, 2018

What did you do?

I am trying to convert a jpeg image of size 63x47 to jpeg2000

What did you expect to happen?

Expected a jp2 image as output. However this issue doesn't happen if both the height and width of the image >= 64

What actually happened?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py", line 1698, in save
    save_handler(self, fp, filename)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Jpeg2KImagePlugin.py", line 264, in _save
    ImageFile._save(im, fp, [('jpeg2k', (0, 0)+im.size, 0, kind)])
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageFile.py", line 500, in _save
    raise IOError("encoder error %d when writing image file" % s)
IOError: encoder error -2 when writing image file

What versions of Pillow and Python are you using?

>>> PIL.PILLOW_VERSION
'3.4.2'
>>> PIL.VERSION
'1.1.7'
pbagrecha-mpb15:~$ python --version
Python 2.7.13

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.

Python 2.7.13 (default, Apr  4 2017, 08:47:57)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> Image.open('image.jpeg').save('image.jp2', 'JPEG2000', quality_mode='dB', quality_layers=[41])

Attaching the image I am trying to convert.
image

@hugovk
Copy link
Member

hugovk commented Jun 8, 2018

Reproducible with Pillow 5.1.0 on Python 3.6.5 and Python 2.7.15 on macOS High Sierra.

@radarhere radarhere changed the title can't convert images with height / width < 64 to jpeg2000 Can't convert images with height / width < 64 to jpeg2000 Jun 8, 2018
@bagipriyank
Copy link
Author

any update on this?

@Iamanorange
Copy link

Reproducible with Pillow 5.3.0 on Python 3.5.2 on Ubuntu 16.04.

@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to Icebox in Pillow May 11, 2019
@radarhere
Copy link
Member

I can't replicate this. I would guess that it's been fixed in OpenJPEG, but to check, @hugovk since you were able to reproduce this previously, could you give it another try?

@hugovk
Copy link
Member

hugovk commented Jul 16, 2019

Cannot reproduce with macOS Mojave 10.14.5, latest Pillow 6.1.0 and openjpeg stable 2.3.1:

115% 1z [hugo:/tmp/Downloads] % p
Python 3.7.4 (default, Jul  9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> Image.open('image.jpeg').save('image.jp2', 'JPEG2000', quality_mode='dB', quality_layers=[41])
>>>82% 1z [hugo:/tmp/Downloads] 8s % p2
Python 2.7.16 (default, Mar  4 2019, 09:02:22)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> Image.open('image.jpeg').save('image.jp2', 'JPEG2000', quality_mode='dB', quality_layers=[41])

The output image.jp2 looks like the input image.jpeg in both cases.

@radarhere
Copy link
Member

Thanks

Pillow automation moved this from Icebox to Closed Jul 16, 2019
@radarhere
Copy link
Member

If anyone else is still experiencing this and would like it looked into further, feel free to comment and this can be re-opened.

@cattybaby723
Copy link

Reproducible with Pillow 8.2.0 on Python 3.7.5 on MacOS Catalina 10.15.7

@radarhere
Copy link
Member

Using the image from the original post? Or another one?

@cattybaby723
Copy link

cattybaby723 commented May 31, 2021

I used my own image and here is my test code.

from PIL import Image
image_path = "small.jpg" # image size is 18 x 28
save_file_path = "test.jp2"
image = Image.open(image_path)
image.save(save_file_path, 'JPEG2000')

Attaching the image I tested.
small

@radarhere radarhere reopened this May 31, 2021
Pillow automation moved this from Closed to New Issues May 31, 2021
@radarhere
Copy link
Member

I've found that OpenJPEG is trying to tell us that "Number of resolutions is too high in comparison to the size of tiles".

I find that setting num_resolutions to a value between 1 and 5 works.

from PIL import Image
image_path = "small.jpeg" # image size is 18 x 28
save_file_path = "test.jp2"
image = Image.open(image_path)
image.save(save_file_path, 'JPEG2000', num_resolutions=5)

@radarhere
Copy link
Member

I've created PR #5540 to fix the default behaviour of Pillow.

Pillow automation moved this from New Issues to Closed Jun 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

6 participants