jpeg rotation confusing output orientation of PDF #151

Open
opened 2 years ago by muccigrosso · 10 comments

I've got a jpeg from an iPhone that has been rotated and has under ImageMagick's identify command an orientation of "Righttop". When I do a simple img2pdf command and have -S A4, hte PDF ends up in landscape rather than portrait mode. If I use A4^T, it ends up with portrait instead of landscape. In both instances, the images is correctly oriented. Altering the image with a rotate in jpegtran gives the image an undefined orientation and the output PDF in that case is fine.

So it seems like the orientation is being applied to the PDF page.

Version 0.4.4

I've got a jpeg from an iPhone that has been rotated and has under ImageMagick's `identify` command an orientation of "Righttop". When I do a simple img2pdf command and have `-S A4`, hte PDF ends up in landscape rather than portrait mode. If I use `A4^T`, it ends up with portrait instead of landscape. In both instances, the images is correctly oriented. Altering the image with a rotate in jpegtran gives the image an `undefined` orientation and the output PDF in that case is fine. So it seems like the orientation is being applied to the PDF page. Version 0.4.4
josch commented 2 years ago
Owner

Can you share an image that you see this effect with?

Can you share an image that you see this effect with?
Poster

Sure. Here's a blurry copy of the one I'm using (which is a photo of a passport). I'm not sure what I did exactly to get it into this form, but surely an iPhone photo that was rotated, probably more than that since it's a jpeg and not heic.

Sure. Here's a blurry copy of the one I'm using (which is a photo of a passport). I'm not sure what I did exactly to get it into this form, but surely an iPhone photo that was rotated, probably more than that since it's a jpeg and not heic.
josch commented 2 years ago
Owner

When I do a simple img2pdf command and have -S A4, hte PDF ends up in landscape rather than portrait mode. If I use A4^T, it ends up with portrait instead of landscape. In both instances, the images is correctly oriented.

If you do not want this behavour, you can run img2pdf with --rotation=none. The default behaviour is to auto rotate the page according to the exif rotation value. Since your image contains exif information saying that the image should be rotated 90° clockwise, you are getting a landscape page even though you told it to use a portrait page and vice-versa.

Would you prefer that img2pdf chooses portrait and landscape depending on what is the most optimal orientation for your photo?

> When I do a simple img2pdf command and have -S A4, hte PDF ends up in landscape rather than portrait mode. If I use A4^T, it ends up with portrait instead of landscape. In both instances, the images is correctly oriented. If you do not want this behavour, you can run img2pdf with `--rotation=none`. The default behaviour is to auto rotate the page according to the exif rotation value. Since your image contains exif information saying that the image should be rotated 90° clockwise, you are getting a landscape page even though you told it to use a portrait page and vice-versa. Would you prefer that img2pdf chooses portrait and landscape depending on what is the most optimal orientation for your photo?
Poster

I guess I don't undersand why img2pdf is rotating the pdf at all. I can add that switch and see what happens.

For me the expected behavior would be to use the page size and orientation in the command, if specified. That is for the pdf. The image should be rotated as its exif data indicates. That's totally separate from the pdf orientation.

In the absence of explicit pdf size and orientation commands, I don't have strong feelings about what to do.

I guess I don't undersand why img2pdf is rotating the pdf at all. I can add that switch and see what happens. For me the expected behavior would be to use the page size and orientation in the command, if specified. That is for the pdf. The image should be rotated as its exif data indicates. That's totally separate from the pdf orientation. In the absence of explicit pdf size and orientation commands, I don't have strong feelings about what to do.
josch commented 2 years ago
Owner

Maybe the --auto-orient option is that does what you expect to happen? If I understood you correctly, I guess you want to run this:

img2pdf blurry.JPEG -S A4 --auto-orient -o out.pdf
Maybe the `--auto-orient` option is that does what you expect to happen? If I understood you correctly, I guess you want to run this: img2pdf blurry.JPEG -S A4 --auto-orient -o out.pdf
Poster

I'll play with this a bit, but I dont think this is what I want.

Instead what I want is, I think, pretty straightforward. If I specify the pdf size and orientation, that is what should result. That's it. The image should stay as it would normally be displayed. The software should not try to secondguess me.

What I get in my original example is that the image stays the same but the pdf page gets rotated. And it gets rotated to be landscape when the image is portrait. That really makes no sense to me. Nor dies the idea that the page would be affected by internal metadata in the photo.

I can see a use for auto-orient, but that is not what I'm after.

I'll play with this a bit, but I dont think this is what I want. Instead what I want is, I think, pretty straightforward. If I specify the pdf size and orientation, that is what should result. That's it. The image should stay as it would normally be displayed. The software should not try to secondguess me. What I get in my original example is that the image stays the same but the pdf page gets rotated. And it gets rotated to be landscape when the image is portrait. That really makes no sense to me. Nor dies the idea that the page would be affected by internal metadata in the photo. I can see a use for auto-orient, but that is not what I'm after.
josch commented 2 years ago
Owner

Right now what is happening is:

  1. you say that you want an "A4" portrait paper
  2. img2pdf renders your photo onto that paper
  3. since by default, the exif information is respected, the paper is turned 90° clockwise

What I think you want (if I understand you correctly) is:

  1. img2pdf uses the exif information of the image to turn it 90° clockwise
  2. you told img2pdf that you want an A4 portrait paper
  3. img2pdf renders the turned image onto that portrait paper

From what I understand you argue with what "feels right" and what is "intuitive". Is there actually any hard reason to go for either the first or the second way of understanding what "rotate automatially according to the exif data" means? Since I wrote this software for me, the first way makes more sense. To you I guess the second. How can we determine if one of the two is objectively (and not just subjectively) better?

Right now what is happening is: 1. you say that you want an "A4" portrait paper 2. img2pdf renders your photo onto that paper 3. since by default, the exif information is respected, the paper is turned 90° clockwise What I think you want (if I understand you correctly) is: 1. img2pdf uses the exif information of the image to turn it 90° clockwise 2. you told img2pdf that you want an A4 portrait paper 3. img2pdf renders the turned image onto that portrait paper From what I understand you argue with what "feels right" and what is "intuitive". Is there actually any hard reason to go for either the first or the second way of understanding what "rotate automatially according to the exif data" means? Since I wrote this software for me, the first way makes more sense. To you I guess the second. How can we determine if one of the two is objectively (and not just subjectively) better?
Poster

I'm not sure we can get all the way to objective goodness, :-) but here is how I conceive of the app working.

I have an image. It looks good to me. I want it in a pdf. I tell img2pdf to put the image on A4 paper that is oriented normally (portrait). That's what happens: I get the image, looking like it did before, in a portrait A4 pdf.

As for the image's exif rotation data...

  1. I usually don't think about it, as happened to me here. The image looks good in every app I view it in. Why should have to think about it? Heck, I might not even know it had been rotated. Should I have to check that before using img2pdf?

  2. Why should the image's exif data affect the pdf? This is the part that I really don't get. The image gets rotated according to its internal metadata. That always happens. Showing it unrotated is (nearly) always wrong. Conceiving of the image without its rotation is an erroneous consideration, I would suggest. I think what you are saying is that in the current model the software ignores the rotation data, places the unrotated image on the requested page and then rotates that whole page plus image. That seems contrary to the idea of putting the image in a pdf of a particular size and orientation via -S and also to the isea that the image is incomplete with rotation metadata.

Maybe part of the conceptual difference is whether you conceive of the software converting an image to a pdf or just putting it into one? I tend to think of the latter.

PS I dont want it to get lost here how much I use this software and find it extremely helpful.

I'm not sure we can get all the way to objective goodness, :-) but here is how I conceive of the app working. I have an image. It looks good to me. I want it in a pdf. I tell img2pdf to put the image on A4 paper that is oriented normally (portrait). That's what happens: I get the image, looking like it did before, in a portrait A4 pdf. As for the image's exif rotation data... 1. I usually don't think about it, as happened to me here. The image looks good in every app I view it in. Why should have to think about it? Heck, I might not even know it had been rotated. Should I have to check that before using img2pdf? 2. Why should the image's exif data affect the pdf? This is the part that I really don't get. The image gets rotated according to its internal metadata. That always happens. Showing it unrotated is (nearly) always wrong. Conceiving of the image without its rotation is an erroneous consideration, I would suggest. I think what you are saying is that in the current model the software ignores the rotation data, places the unrotated image on the requested page and then rotates that whole page plus image. That seems contrary to the idea of putting the image in a pdf of a particular size and orientation via -S and also to the isea that the image is incomplete with rotation metadata. Maybe part of the conceptual difference is whether you conceive of the software converting an image to a pdf or just putting it into one? I tend to think of the latter. PS I dont want it to get lost here how much I use this software and find it extremely helpful.
josch commented 2 years ago
Owner

Thank you for bringing up this issue and explaining it to me.

I have to think more about this because this is a big change in how the options work together and existing users of this library might expect the current behaviour. I will keep this issue open until I find a solution that satisfies me.

Thank you for bringing up this issue and explaining it to me. I have to think more about this because this is a big change in how the options work together and existing users of this library might expect the current behaviour. I will keep this issue open until I find a solution that satisfies me.
Poster

Thanks for the reply.

I finally got a little time to play with the suggestions you made above.

--rotation=none ignores the exif orientation data, which is not what I want.

-a with -S A4 does give me the result I want, as long as I don't want to put the image on a landscape page, since it forces the A4 to portait. At least the image is the right-way up.

Based on the above, I guess what I'm asking is to be able to determine exactly what page size and orientation img2pdf will output without knowing anything about the exif tags on a given image. Again, I would have thought that dictating the page and orientation via -S would do that.

It strikes me that there is an inherent potential conflict between -S and -a in that the latter will override the former, if the image is not oriented the way the pdf is supposed to be.

Thanks for the reply. I finally got a little time to play with the suggestions you made above. `--rotation=none` ignores the exif orientation data, which is not what I want. `-a` with `-S A4` does give me the result I want, as long as I don't want to put the image on a landscape page, since it forces the A4 to portait. At least the image is the right-way up. Based on the above, I guess what I'm asking is to be able to determine exactly what page size and orientation img2pdf will output **without** knowing anything about the exif tags on a given image. Again, I would have thought that dictating the page and orientation via `-S` would do that. It strikes me that there is an inherent potential conflict between `-S` and `-a` in that the latter will override the former, if the image is not oriented the way the pdf is supposed to be.
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#151
Loading…
There is no content yet.