Is it really necessary to raise an Exception for invalid exif data? #100

Closed
opened 2021-05-13 10:14:50 +00:00 by mara0004 · 7 comments
Contributor

I regularly get sent files containing the invalid exif rotation value 0 (only 1-8 is acceptable according to the specification). All other programs handle these files without trouble and just assume no rotation. Img2pdf stops with an ExifOrientationError, though.
I have now added a pre-processing code to my program that removes invalid exif data using piexif + tempfiles, but I quite dislike this workaround, some key reasons are:

  • an additional dependency is required
  • it muddles up the code, making it harder to overview
  • and most importantly, it negatively impacts performance

Is it really necessary to raise an Exception for invalid rotation data? Wouldn't it be enough to just print a warning and continue?

Relevant code passage

see also: #61

I regularly get sent files containing the invalid exif rotation value 0 (only 1-8 is acceptable according to the specification). All other programs handle these files without trouble and just assume no rotation. Img2pdf stops with an ExifOrientationError, though. I have now added a pre-processing code to my program that removes invalid exif data using piexif + tempfiles, but I quite dislike this workaround, some key reasons are: - an additional dependency is required - it muddles up the code, making it harder to overview - and most importantly, it negatively impacts performance Is it really necessary to raise an Exception for invalid rotation data? Wouldn't it be enough to just print a warning and continue? [Relevant code passage](https://gitlab.mister-muffin.de/josch/img2pdf/src/branch/main/src/img2pdf.py#L1209) see also: https://gitlab.mister-muffin.de/josch/img2pdf/issues/61
Author
Contributor

IMHO, reporting the problem to the manufacturers of phones / cameras that produce these invalid rotation values is not a promising approach, because

  • they don't have publicly accessible bug trackers
  • they likely won't respond to e-mails at all
  • even if they would publish a new software to fix the problem, many users might not update
IMHO, reporting the problem to the manufacturers of phones / cameras that produce these invalid rotation values is not a promising approach, because - they don't have publicly accessible bug trackers - they likely won't respond to e-mails at all - even if they would publish a new software to fix the problem, many users might not update
Owner

I see the problem. I think I can be convinced to add an option to img2pdf which allows to ignore the exif rotation. And if rotation is ignored, it also doesn't make sense to error out on invalid rotation values.

I see the problem. I think I can be convinced to add an option to img2pdf which allows to ignore the exif rotation. And if rotation is ignored, it also doesn't make sense to error out on invalid rotation values.
Author
Contributor

Thank you, this would already be an acceptable solution.
However, completely ignoring exif rotation is not exactly what I was looking for. I rather meant an option to fall back to no rotation if the exif value is invalid or unsupported. If there is a valid rotation tag, I'd like to use it.

Thank you, this would already be an acceptable solution. However, completely ignoring exif rotation is not exactly what I was looking for. I rather meant an option to fall back to no rotation if the exif value is invalid or unsupported. If there is a valid rotation tag, I'd like to use it.
Owner

This pains me. If I tell a program "use the exif data for rotation" and the exif rotation data is invalid, then I expect the program to fail because it cannot fulfill my request. I understand that you want a "use exif data for rotation if the exif information is valid". How about an option like this:

--rotation [auto|none|ifvalid|0|90|180|270]
  • "auto" is the current behaviour and will error out on faulty exif data
  • "none" disables rotation and ignores faulty exif data
  • "ifvalid" is the behaviour you want and will issue a warning if the exif data is invalid
  • 0, 90, 180, 270 are fixed rotation values

The same functionality would of course be exposed in the library interface.

This pains me. If I tell a program "use the exif data for rotation" and the exif rotation data is invalid, then I expect the program to fail because it cannot fulfill my request. I understand that you want a "use exif data for rotation if the exif information is valid". How about an option like this: --rotation [auto|none|ifvalid|0|90|180|270] * "auto" is the current behaviour and will error out on faulty exif data * "none" disables rotation and ignores faulty exif data * "ifvalid" is the behaviour you want and will issue a warning if the exif data is invalid * 0, 90, 180, 270 are fixed rotation values The same functionality would of course be exposed in the library interface.
Author
Contributor

Yes, that looks very good.

Yes, that looks very good.
Owner

@mara0004 Do you happen to have examples of software, cameras or phones that do set the invalid exif rotation of zero?

@mara0004 Do you happen to have examples of software, cameras or phones that do set the invalid exif rotation of zero?
josch closed this issue 2021-05-14 09:32:41 +00:00
Author
Contributor

@mara0004 Do you happen to have examples of software, cameras or phones that do set the invalid exif rotation of zero?

Yes. According to the exif data, the problematic files I have were produced by a Huawei VOG-L29 phone. The detailed version string is 10.1.0.181(C431E23R2P5). Though the cause might also be the application the pictures were taken (or edited) with, this I do not know.

> @mara0004 Do you happen to have examples of software, cameras or phones that do set the invalid exif rotation of zero? Yes. According to the exif data, the problematic files I have were produced by a `Huawei VOG-L29` phone. The detailed version string is `10.1.0.181(C431E23R2P5)`. Though the cause might also be the application the pictures were taken (or edited) with, this I do not know.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#100
No description provided.