#๐Ÿ”’ pillow: Opening 4012x6034 PNG returns a 120x160 image.

14 messages ยท Page 1 of 1 (latest)

weak inletBOT
#

@wheat warren

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wheat warren
#

Why was my message deleted...

serene dirge
#

usually a bot sends you a message when that happens, and it explains why

wheat warren
#

In summary...

When I try to load a 4012x6034 PNG, pillow returns a 120x160 image instead, with black bars padding out the width (as with 160 height, width should only be ~106.4).

Code:

from PIL import Image

image = Image.open(<path>)

Alternative code:

import io
from PIL import Image

image_data = io.BytesIO()
with open(<path>, 'rb') as f:
    image_data.write(f.read())
image = Image.open(image_data)

I wanted to include the image file but I don't think there's a way for me to send it as-is. My message got deleted because I zipped it.

#

pillow: Opening 4012x6034 PNG returns a 120x160 image. (Content in replies)

#

Not sure if Discord is going to futz with the raw image data, but since I can't package it and send it (thanks PythonBot), this is the best I can do unless someone requests the image in DMs.

#

Well, it seems like Discord can't even display the image so the image is clearly special.

However, I can open it on my computer just fine. It reads as standard RGB encoding (24 bit).

#

Out of curiosity, I'd like to hear if any of you guys can see the image or not (and what platform you're on).

wheat warren
#

ffprobe (and ffmpeg for that matter) are only showing a tiff monob 160x120 stream... nothing else.

However, there definitely is more to the image because even Window's own photos app can read it just fine. And Windows is normally the last thing I'd expect to be able to read any non-standard media files.

wheat warren
#

I'll play around with it more tomorrow... But I think the PNG file may actually be a RAW (likely NEF). No idea why the file type is PNG, but the more I learn about media formats, the more I realize file types are often just a package and the data inside can be encoded in a bunch of different ways.

trail egret
# wheat warren I'll play around with it more tomorrow... But I think the PNG file may actually ...

Yeah, this looks to be a NEF file (given the EXIF says it was output on a Nikon camera using Ver.1.03 software, apparently). It's just a very special version of a TIFF file that tools like Pillow cannot handle properly. What is being loaded is the 160x120 thumbnail because Pillow and the tools I tried think it's a "reduced image" and don't bother to look at the rest of the "child images". (here's a related issue on the project)

trail egret
weak inletBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.