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

Closed
opened 3 years ago by mara0004 · 7 comments

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
Poster

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
josch commented 3 years ago
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.
Poster

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.
josch commented 3 years ago
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.
Poster

Yes, that looks very good.

Yes, that looks very good.
josch commented 3 years ago
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 3 years ago
Poster

@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
Loading…
There is no content yet.