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 TIFF as JPEG causes malformed image #7062

Closed
gverm opened this issue Apr 3, 2023 · 2 comments
Closed

Saving TIFF as JPEG causes malformed image #7062

gverm opened this issue Apr 3, 2023 · 2 comments

Comments

@gverm
Copy link

gverm commented Apr 3, 2023

What did you do?

Tried saving TIFF as JPEG.

What did you expect to happen?

JPEG to look the same as TIFF.

What actually happened?

Save exits successfully, but image looks malformed.

What are your OS, Python and Pillow versions?

  • OS: EndeavourOS/Alpine Linux
  • Python: 3.10/3.11
  • Pillow: 9.5.0
from PIL import Image
src_img = Image.open("e7fe2857104360d68e6b7c51f9f0a5a5-MA_ROM_VII_FO_0069.tif")
dst_img = src_img.convert("RGB")
dst_img.save("test.jpg", quality=95)

Original image
converted JPEG

The mode of the original TIFF is I;16 and I've read that this is only partially supported. I've tried looking through the issues to see if I could find a reason why this doesn't work and it seems #1888 might be related, but I'm not sure.

EDIT: forgot to mention, using OpenCV to convert works correctly.

@hugovk hugovk added the TIFF label Apr 3, 2023
@radarhere
Copy link
Member

#3159 is the relevant open issue.

If you're looking for an immediate solution, I can offer the following code.

from PIL import Image
src_img = Image.open("e7fe2857104360d68e6b7c51f9f0a5a5-MA_ROM_VII_FO_0069.tif")
if src_img.mode == "I;16":
	src_img = src_img.point(lambda i: i * (1 / 255))
dst_img = src_img.convert("RGB")
dst_img.save("test.jpg", quality=95)

@gverm
Copy link
Author

gverm commented Apr 3, 2023

Thanks @radarhere that works. I'll close this as a duplicate of #3159 then.

@gverm gverm closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
@radarhere radarhere added Conversion and removed TIFF labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants