Skip to content

PlanarConfiguration save #3622

Description

@VariableDeclared

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')

Activity

  1. cgohlke commented on Jan 31, 2019

    @cgohlke
    Contributor

    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.

  2. radarhere commented on Feb 1, 2019

    @radarhere
    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?

  3. cgohlke commented on Feb 1, 2019

    @cgohlke
    Contributor

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

  4. radarhere commented on Feb 1, 2019

    @radarhere
    Member

    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')
  5. changed the title [-]TIF Images corrupt after Image.save()[/-] [+]PlanarConfiguration save[/+] on Aug 21, 2019
  6. radarhere commented on Jan 18, 2022

    @radarhere
    Member

    I've created #5973 to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions