allgood / OpenNoteScanner

Android application for scanning and manipulating handwritten notes and documents.
Other
1.32k stars 278 forks source link

Images are set with invalid orientation EXIF tag #248

Open xeals opened 3 years ago

xeals commented 3 years ago

Captured images are set with an Orientation EXIF flag of 0. This is an invalid value and will cause issues in applications that do not handle it.

Steps to reproduce

Take a photo and check its Orientation EXIF tag.

Expected behaviour

Orientation flag is set to a valid value. As photos are not rotated regardless of phone orientation, it should probably always be the default portrait (1).

Actual behaviour

Orientation flag is set to 0.

sphh commented 3 years ago

I just ran into the same problem: I scan the notes with OpenNoteScanner, transfer the .jpg files to my computer and use img2pdf to convert them to pdfs. img2pdf complains with

ERROR:root:error: Invalid rotation (0)

I think, @xeals suggestion to set the Orientation EXIF tag to 1 is a good one.

cdpb commented 2 years ago

I think, @xeals suggestion to set the Orientation EXIF tag to 1 is a good one.

exiv2 -M"set Exif.Image.Orientation 1" *.jpg

... for reference

kimek commented 1 year ago

Don't set orientation in exif to 1 as this will flip your image after using img2pdf In man img2pdf -r ROT, --rotation ROT, --orientation ROT Specifies how input images should be rotated. ROT can be one of auto, none, ifvalid, 0, 90, 180 and 270. The default value is auto and indicates that input images are rotated according to their EXIF Orientation tag. The values none and 0 ignore the EXIF Orientation values of the input images. The value ifvalid acts like auto but ignores invalid EXIF rotation values and only issues a warning instead of throwing an error. This is useful because many devices like Android phones, Canon cameras or scanners emit an invalid Orientation tag value of zero. The values 90, 180 and 270 perform a clockwise rotation of the image. Therefore use flag --rotation=none if cli or python example: (fearis nickname ) https://stackoverflow.com/questions/60384205/invalid-rotation-when-converting-jpg-to-pdf-with-python/74707233#74707233

More on oficial page: https://github.com/josch/img2pdf#bugs

Remember that rotation argument is quiet new, is in 4.02 version of img2pdf (as I remember), newest is 4.04

sphh commented 1 year ago

@kimek: So it would be

exiv2 -M"del Exif.Image.Orientation" *.jpg

before running img2pdf?

@allgood: Do you think, it is possible to remove the Orientation tag from the scanned images automatically?

kimek commented 1 year ago

@sphh Yes, that would work to. I've just tested that with img2pdf ver 3 which doesnt support rotation. In this case deleting orientation would be easier. Good point. However... ideally you should avoid situation where "cause of 3rd party program you need to change your files". Just be aware about deleting exif data, as there is no point of return