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

JPEGs from my Panasonic camera are erroneously recognised as MPOs #1198

Closed
pdc opened this issue Apr 16, 2015 · 7 comments
Closed

JPEGs from my Panasonic camera are erroneously recognised as MPOs #1198

pdc opened this issue Apr 16, 2015 · 7 comments
Labels
Bug Any unexpected behavior, until confirmed feature.

Comments

@pdc
Copy link

pdc commented Apr 16, 2015

If I load a JPEG from my camera (a Panasonic DSC GX7) the format is reported as MPO not JPEG. The seek method erroneously allows me to select the nonexistent second frame. For example:

>>> x = Image.open('/Users/pdc/Pictures/Samples/P1010238.JPG')
>>> x.format
'MPO'
>>> x.seek(1)
>>> x.getpixel((0, 0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pdc/virtualenvs/photocrowd/lib/python2.7/site-packages/PIL/Image.py", line 1189, in getpixel
    self.load()
  File "/Users/pdc/virtualenvs/photocrowd/lib/python2.7/site-packages/PIL/ImageFile.py", line 229, in load
    "(%d bytes not processed)" % len(b))
IOError: image file is truncated (349 bytes not processed)

I discovered this because our site checks uploads are JPEGs and the check failed because the format is returned as MPO.

Given how haphazardly image metadata formats are specified and implemented it is possible that Panasonic’s JPEGs do in fact report 2 frames for some reason. In this case it might be worth detecting this case because the second frame does not appear to exist.

@hugovk
Copy link
Member

hugovk commented Apr 17, 2015

This came up recently. Can you check this? #1138 (comment)

@pdc
Copy link
Author

pdc commented Apr 17, 2015

You are correct, #1138 is the same issue.

To clarify, it is definitely something to do with the way certain cameras write their JPEGs: if I load the image in to an editor & save it it is recognized as a JPEG as expected.

The workaround for me is to allow MPO as a synonym for JPEG. But other sites may have also been broken by this and not noticed yet!

There is a general issue (which is outside the scope of this issue) that recognizing formats by simple names does not work in a world where people come up with formats that are intended to be mistaken for other formats most of the time. The ultimate fix would need to be the equivalent of a class hierarchy, where I could ask 'Is this JPEG?' and get a yes if it is JPEG or any of the ‘subformats’ of JPEG. Either that or have the format reported as JPEG, and have a ‘features’ or ‘flavour’ list that includes the MPO token? But that would annoy people who are expecting format MPO.

@hugovk
Copy link
Member

hugovk commented Apr 17, 2015

At least in #1138 (comment) the Pillow finds a NumberOfImages tag (tag ID = 45057 = 0xB001, see page 11 of the MPO spec) with a value of 2. My guess is the second frame is a thumbnail.

If I run exiftool on it, I get these (amongst other rows):

ExifTool Version Number         : 9.46
File Name                       : bob 15.jpg
Directory                       : .
File Size                       : 5.2 MB
File Modification Date/Time     : 2015:03:20 13:31:03+02:00
File Access Date/Time           : 2015:03:20 13:31:03+02:00
File Creation Date/Time         : 2015:03:20 13:31:03+02:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Image Description               :
Make                            : SONY
Camera Model Name               : DSC-W530
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Modify Date                     : 2015:03:09 20:47:22
Y Cb Cr Positioning             : Co-sited
Exposure Time                   : 1/160
F Number                        : 3.2
Exposure Program                : Program AE
ISO                             : 100
Exif Version                    : 0221
Date/Time Original              : 2015:03:09 20:47:22
Create Date                     : 2015:03:09 20:47:22
Components Configuration        : Y, Cb, Cr, -
Compressed Bits Per Pixel       : 3
Exposure Compensation           : 0
Max Aperture Value              : 2.7
Metering Mode                   : Multi-segment
Light Source                    : Unknown
Flash                           : Off, Did not fire
Focal Length                    : 6.7 mm
Creative Style                  : Standard
Macro                           : Off
Focus Mode                      : Permanent-AF
AF Area Mode                    : Face Tracking
AF Illuminator                  : Auto
JPEG Quality                    : Standard
Flash Level                     : Normal
Release Mode                    : Normal
Sequence Number                 : Single
Anti-Blur                       : Off
Dynamic Range Optimizer         : Standard
High ISO Noise Reduction 2      : Normal
Intelligent Auto                : On
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 4320
Exif Image Height               : 3240
Interoperability Index          : R98 - DCF basic file (sRGB)
Interoperability Version        : 0100
File Source                     : Digital Camera
Scene Type                      : Directly photographed
Custom Rendered                 : Normal
Exposure Mode                   : Auto
White Balance                   : Auto
Scene Capture Type              : Standard
Contrast                        : Normal
Saturation                      : Normal
Sharpness                       : Normal
PrintIM Version                 : 0300
Compression                     : JPEG (old-style)
Thumbnail Offset                : 5700
Thumbnail Length                : 8397
MPF Version                     : 0100
Number Of Images                : 2
MP Image Flags                  : Dependent child image
MP Image Format                 : JPEG
MP Image Type                   : Large Thumbnail (full HD equivalent)
MP Image Length                 : 621306
MP Image Start                  : 4850597
Dependent Image 1 Entry Number  : 0
Dependent Image 2 Entry Number  : 0
Image UID List                  : (Binary data 66 bytes, use -b option to extract)
Total Frames                    : 1
Image Width                     : 4320
Image Height                    : 3240
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:2 (2 1)
Aperture                        : 3.2
Image Size                      : 4320x3240
Preview Image                   : (Binary data 621306 bytes, use -b option to extract)
Shutter Speed                   : 1/160
Thumbnail Image                 : (Binary data 8397 bytes, use -b option to extract)
Focal Length                    : 6.7 mm
Light Value                     : 10.7

So that considers it a JPEG, but with MPO stuff.

Our MpoImageFile is a subclass of JpegImageFile so you can still do JPEG things to it.

@aclark4life
Copy link
Member

Duplicate of #1138?

@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label Jun 28, 2015
@pdc
Copy link
Author

pdc commented Jul 17, 2015

The code is not incorrect to recognise the photo as an MPO given there are no well-defined standards.

There is still the design problem of how the API can answer the question ‘Is this a JPEG?’ given that merely checking whether the format attribute is JPEG is not sufficient. But that is outside the scope of this issue.

@pdc pdc closed this as completed Jul 17, 2015
@JamesJGarner
Copy link

This is still broken

@radarhere
Copy link
Member

The comment from @JamesJGarner is addressed in #4603

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

No branches or pull requests

5 participants