blueimp / JavaScript-Load-Image

Load images provided as File or Blob objects or via URL. Retrieve an optionally scaled, cropped or rotated HTML img or canvas element. Use methods to parse image metadata to extract IPTC and Exif tags as well as embedded thumbnail images, to overwrite the Exif Orientation value and to restore the complete image header after resizing.
https://blueimp.github.io/JavaScript-Load-Image/
MIT License
4.45k stars 922 forks source link

Two orientation #103

Closed kiyeon-jo closed 4 years ago

kiyeon-jo commented 4 years ago

Thank you always.

Your library reads only one orientation.

Of course, it is normal to have only one.

Unfortunately, if you rotate in the Microsoft Windows Photo Viewer, you will have two orientation records.

Can't you provide two pieces of information?

For your information, http://exif.regex.info/exif.cgi is showing two orientation information here.

kiyeon-jo commented 4 years ago

Sample image with two orientation 2020042211301336382

kiyeon-jo commented 4 years ago

uploaded photo exif.get('Software') => "Microsoft Windows Photo Viewer 6.1.7600.16385"

Usually read the last 'orientation' value when inserting an image into the browser.

blueimp commented 4 years ago

Thanks for the report @kiyeon-jo.

I can confirm that your sample image does indeed contain two Orientation values.

Curious, I'm not aware of the EXIF standard supporting two values for the same tag number in the same Image File Directory.

exiftool, which I consider as the standard tooling for EXIF, also only reports the last Orientation value when used on your sample image:

exiftool -Orientation image.jpg
Orientation                     : Horizontal (normal)

Technically it would be possible to collect all values for the same tag, but it's not clear how this data should be returned and consuming code would be surprised if the return value has a different type (e.g. an Array of two values instead of a single value).

Since the last Orientation value is also the correct one, I'm assuming that is expected behavior, so I'm inclined to close this ticket.

flexilivre commented 4 years ago

Hi @blueimp ,

You are right, the problem I encounter seems to be a case of duplicate orientation values.

When I use the function here , I get the orientation that is right in my case. Would it be a good idea to use this code in your library in order to solve such case ?

Here the result from exiftool :

exif

And last thing, I think the problem occurs for the same reason as for kiyeon-jo : Software : Microsoft Windows Photo Viewer 6.1.7600.16385

blueimp commented 4 years ago

Thanks again for your report @flexilivre. I'm now thinking that it might be valid to store a second Orientation value for the Thumbnail data. I'll look into this and will likely release an update.

blueimp commented 4 years ago

I learned now that the Thumbnail directory (IFD1) can contain all Exif tags that appear in the main image meta data directory (IFD0), so storing them in the same map created override issues.

I've released a new version that stores the IFD1 (Thumbnail) data in a separate ExifMap: https://github.com/blueimp/JavaScript-Load-Image/blob/master/README.md#exif-thumbnail

Thanks to this change, the thumbnail Orientation will not override the original image Orientation anymore and should fix the issues both of you encountered.

Here's how to retrieve both Orientation values:

exif.get('Orientation')
exif.get('Thumbnail').get('Orientation')

Thanks again for your help @kiyeon-jo and @flexilivre!