-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
JPEG image being identified as MPO #1138
Comments
Works for me. I can't reproduce:
What Pillow and operating system version? |
May be something to do with MPO sharing a factory with JPEG? E.g. https://github.com/python-pillow/Pillow/blob/master/PIL/MpoImagePlugin.py#L38 |
MPO is pretty similar to JPEG, there's an exif tag that determines it, and then there's a bit extra in the data. If we detect MPO, we should be able to decode it. OTOH, I'm not totally sure what Pillow would do with an MPO file before we had support for it. Edit: not seeing it here either. |
@wiredfool I wonder what accounts for the difference in results between myself and @xtagon. If I could reproduce, that would indicate Pillow's failure to identify the JPEG correctly. Since I can't, I wonder if some environmental factor is having some effect e.g. operating system, Pillow version, etc. |
@aclark4life I'm double checking my environment/versions, and I'll check to see if Google Drive altered the file at all too. Stand by. |
OS: GNU/Linux Gentoo 3.12.13 locally, and the server that found the issue is Ubuntu 14.04.1 LTS Okay...I pip installed Pillow 2.7.0, but PIL.VERSION in the Python REPL says 1.1.7 - is it installing the wrong version, and why would it? I tried uninstalling with pip and installing, and also tried installing from requirements.txt. I'm still able to reproduce with this image, even if I re-download it from Google Drive, so Drive isn't altering it like I thought it might be. |
How about PIL.PILLOW_VERSION? |
Ah, thank you, that does return '2.7.0' |
Your REPL says "darwin" suggesting you're on a Mac, could you try to reproduce on Linux? |
Yep, same thing. Can't reproduce:
Sorry! Not sure what is going on. |
Reproducible on Windows 7:
|
Further, in JpegImagePlugin.py's https://github.com/python-pillow/Pillow/blob/master/PIL/JpegImagePlugin.py#L718
|
Also reproducible in a Ubuntu 12.04 LTS VM:
When downloading the test image from Google Docs, make sure to click the down-arrow in the top bar to get the 5.21 MB (4320x3240) original and not the 265 KB (1105x829) resized one. |
@aclark4life have you downloaded original image or just save the preview from Google Docs? |
MPO is pretty same as JPEG. I just added MPO to the list of supported formats when upgraded to 2.7. But I also think what there should no be different in indication for MPO and JPEGs files. They are both JPEGs. |
Ah! Now I get it, thanks all. So on to the actual problem I guess. 😄 |
@xtagon Sorry about that! I should have examined the image better. |
@aclark4life No problem, glad you can reproduce now :) |
So correct me if I'm wrong, an MPO is still a valid JPEG but with extra data (more image frames)? Perhaps Pillow could report the format as JPEG but set an extra flag that indicates that it's an MPO? |
I suspect that if you did something like:
before importing any images, you'd never get an MPO file out of it. |
|
oops, try |
Woohoo, that returned JPEG! Let me find out if this monkeypatch is workable in Pilbox and get back to you |
@wiredfool I dropped those lines into the top of Pilbox's config.py file, and guess what? It resized my MPO problem image just fine! Thank you so much! |
Sweet. |
🍻 |
The same issue now comes up in phatch under Ubuntu (16.04 and 16.10). |
See details in python-pillow/Pillow#1138
So this is still happening. PIL.PILLOW_VERSION = 5.0.0 |
I recently hit a similar problem where a malformed JPG file was identified as an MPO file. Oddly, |
I ran into the same problem of a JPG being identified as MPO, and solved adding to script from PIL import JpegImagePlugin
JpegImagePlugin._getmp = lambda x: None as suggested above. After such addition the JPG file format was correctly identified. |
For users still encountering this issue, please attach a copy of the problem image. |
@radarhere |
When I run
You can read in the Multi-Picture format documentation about the 'Dependent child image' and 'Large Thumbnail' values. If you feel that it should be a JPEG because the extension is '.jpg', the same documentation states that
Also, as a general rule, Pillow does not interpret images according to their file extensions. It reads the data and acts accordingly. So I think this is indeed an MPO. |
@radarhere from PIL import JpegImagePlugin
JpegImagePlugin._getmp = lambda x: None to my script? |
The MPO format is based on JPEG. By adding that line of code in, you're overriding the method that detects if it is an MPO instead of a JPEG. Pillow/src/PIL/JpegImagePlugin.py Lines 800 to 803 in 53ce23c
As to why ImageMagick doesn't identify it, I would guess it's because MPO is not in their list of supported formats - https://imagemagick.org/script/formats.php |
@radarhere |
...actually (and you might think this is crazy), from the way that I read the spec (or the simpler https://wiki.mobileread.com/wiki/MPO), your image is a Baseline MP, which should have a JPG extension. So the extension isn't incorrect - it's just that not every file with a JPG extension is purely in the JPEG format. If there's something that you feel like you can't do with an MPO with Pillow that you can do with a JPEG in Pillow, let us know. |
… creating tf records because of this problem python-pillow/Pillow#1138, just fixed it up
… creating tf records because of this problem python-pillow/Pillow#1138, just fixed it up (#5)
Some cameras store multiple images in JPEG photos, using the MPO format in EXIF metadata. As Pillow supports this format, it sets the "MPO" format attribute to the image object, not the "JPEG" one. This leads to a useless PNG conversion, as MPO are (often, always?) supposed to be "normal" JPEG files. See python-pillow/Pillow#1138. Fix #1777.
i'm on pillow 10.2.0 |
Using exiftool to inspect your image, it says it is a 'Dependent child image'. You can read in the Multi-Picture format documentation about the 'Dependent child image' and 'Large Thumbnail' values. If you feel that it should be a JPEG because the extension is '.jpg', the same documentation states that
Also, as a general rule, Pillow does not interpret images according to their file extensions. It reads the data and acts accordingly. So I think this is indeed an MPO. What makes you think it is not? If I run from PIL import Image
with Image.open("input.jpeg") as im:
print(im) with your image, I get When I open your in macOS Preview, or inspect it with exiftool, they both say the image is 4912px by 3264px. So I don't see a discrepancy in the size. What were you expecting? If it is different than my experience, what program are you using that makes you think it should be a different size? I've created #7821 to fix the |
#7821 has now been merged. |
Lastly i found that iphone's "live photo" is detecting as MPO. (Btw, its little tricky to get original file. If you try to send it with AirDrop - it will convert to HEIC (HEIF). When you try to send it like a file with for .e.g. Telegram - it will ask you to choose HEIC or JPEG. So the only way i found - send it as raw http form upload data. This is my case) @wiredfool's trick switch |
If you'd like to upload an image here, we can take a look at it, but do you have any reason to believe it's not an MPO? As I've said, MPO images might still have a '.jpg' extension
https://pillow.readthedocs.io/en/stable/reference/ImageShow.html states that
The fact that the PNG format is used is intended as a feature, not a bug. Pillow supports some obscure formats, and not all applications support opening them. For example, on my Mac, Preview can't display MIC files, but it can display PNG files. By standardising the format, the support becomes better. 'But wait', you say, 'JPEG isn't obscure!' - true, but JPEG is a lossy format. This means that when an image is saved, it doesn't come out exactly the same. PNG, however, is lossless, meaning it does. https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.show says im.show() is
If I'm debugging an image, I want the saved file to be exactly the same, not slightly different. If you really do want to be able to from PIL import Image, ImageShow
im = Image.open("Tests/images/hopper.jpg")
viewer = ImageShow.MacViewer()
del viewer.options["save_all"]
viewer.format = "JPEG"
viewer.show(im) |
Hi,
We're using Pilbox which depends on Pillow and performs image resizing as a service. A few of our images in production are failing because Pillow is returning the image format as MPO and not JPEG, so Pilbox throws an error because MPO is not a supported format.
The image identifies as a JPEG in ImageMagick, PhotoShop, etc. and opens fine in those programs as a JPEG. However, if we open the failing image in PhotoShop and save a new copy as a new JPEG file, the new image no longer reproduces the issue. Obviously there's something funky going on with the image file, but we can't identify what.
Here is a minimal test case showing the issue:
Image (should be JPEG, identifies as MPO): https://drive.google.com/file/d/0Bx-VFyfqu1DlaFlKVVk1ZDh6S2lPbGFwNUFlN3liQW1PRER3/view?usp=sharing
Save the image to example.jpg and the python script to jpeg_mpo_test.py, and run:
It prints "MPO" and not "JPEG".
We'd really appreciate any help in figuring this out as we are depending on these libraries on some live apps. Let me know what other information you need. Thanks in advance!
The text was updated successfully, but these errors were encountered: