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

PlanarConfiguration save #3622

Closed
VariableDeclared opened this issue Jan 30, 2019 · 5 comments · Fixed by #5973
Closed

PlanarConfiguration save #3622

VariableDeclared opened this issue Jan 30, 2019 · 5 comments · Fixed by #5973
Labels
Projects

Comments

@VariableDeclared
Copy link

VariableDeclared commented Jan 30, 2019

What did you do?

  • Open a file using Pillow Image.open im = Image.open(..blah)
  • downscale the image using Image.thumnail im.thumbnail(..blah)
    • (Args: (512, 512), Image.ANTIALIAS)
  • Save the image using save function, only passing new file name im.save('file_two.tif/tiff') - Same issue for tiff and tif.

What did you expect to happen?

Image would be saved, scaled down, and viewable.

What actually happened?

Image was downscaled, but corrupt, appears red and pixellated, cannot be opened in some image viewers.

Note: I cannot repeat this on Mac OS, haven't tried this on Debian... yet.

What are your OS, Python and Pillow versions?

  • OS: Windows 10 Version 10.0.17763 Build 17763
  • Python: Python 3.6.8
  • Pillow: Pillow 5.4.1

Corrupted Image

from PIL import Image
import os


mode = input("Enter mode")

files = [f for f in os.listdir('./{}'.format(mode)) if os.path.isfile(os.path.join('./{}'.format(mode), f))]

im = Image.open('./{}/{}'.format(mode, files[0]))
im.show()

input()
im.thumbnail((512, 512), Image.ANTIALIAS)

im.save('./PILissue.tiff')
@cgohlke
Copy link
Contributor

cgohlke commented Jan 31, 2019

The PlanarConfiguration tag value is wrong. It should be CONTIG (but is SEPARATE). You can verify by patching the example file with a hex editor at position 126 from 2 to 1.

@radarhere radarhere added the TIFF label Feb 1, 2019
@radarhere
Copy link
Member

You've provided a copy of the output image. Are you able to provide a copy of one of the images that you are running this script over?

@cgohlke
Copy link
Contributor

cgohlke commented Feb 1, 2019

It seems any input image with PlanarConfiguration=2 will trigger this bug.

@radarhere
Copy link
Member

radarhere commented Feb 1, 2019

Ok, thanks. On macOS 10.14, if I try to save https://github.com/python-pillow/Pillow/blob/master/Tests/images/tiff_tiled_planar_raw.tif I get a black image.

im = Image.open('tiff_tiled_planar_raw.tif')
im.save('out.tif')

Presuming that this is the same issue, if you're interested in an immediate solution, I would recommend adding in im._planar_configuration = 1 -

from PIL import Image
import os


mode = input("Enter mode")

files = [f for f in os.listdir('./{}'.format(mode)) if os.path.isfile(os.path.join('./{}'.format(mode), f))]

im = Image.open('./{}/{}'.format(mode, files[0]))
im.show()

input()
im.thumbnail((512, 512), Image.ANTIALIAS)
im._planar_configuration = 1
im.save('./PILissue.tiff')

@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@radarhere radarhere changed the title TIF Images corrupt after Image.save() PlanarConfiguration save Aug 21, 2019
@radarhere
Copy link
Member

I've created #5973 to fix this.

Pillow automation moved this from In progress to Closed Mar 27, 2022
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.

3 participants