Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect auto-orientation when resize is applied #7277

Closed
mcu70 opened this issue Apr 30, 2024 · 2 comments
Closed

Incorrect auto-orientation when resize is applied #7277

mcu70 opened this issue Apr 30, 2024 · 2 comments

Comments

@mcu70
Copy link

mcu70 commented Apr 30, 2024

ImageMagick version

7.1.1-29

Operating system

Linux

Operating system, version and so on

openSUSE Leap v15.5

Description

I have in input a picture which is reported by exiftool as:

Image Size: 4208x3120
Orientation: Mirror horizontal and rotate 270 CW

This means that it was taken with a front camera (so the mirror) and, due to the spatial orientation of the smartphone, it was shooted as landscape but in reality it is a portrait.
Using any random viewer, it is correctly handled and it is shown as a portrait image 3120x4208.
The goal is to resize the picture to a portrait of <768px> x <whatever_to_keep_aspect_ratio> but it cannot be done by using -auto-orient together with -resize.
See below.

Steps to Reproduce

This is the command line that I use and that, in general with different orientations, works fine:

convert -limit disk 100GiB -limit map 24GiB -limit memory 38GiB -limit area 38GB -limit time 14699 -limit thread 4 -density 72 -antialias -background 'white' -flatten -auto-orient 'mirrored_and_rotated_270_CW-original.jpg' -alpha 'remove' -resize '768x' -quality '85' -antialias -verbose -version 'mirrored_and_rotated_270_CW-resized.jpg' 2>&1

As you can see, I'm using the -auto-orient option together with the -resize 768x so that I expect that the image is first mirrored and rotated to become portrait from landscape and, after that, I expect that the TOP side is 768px wide.

Unfortunately, it is the height that becomes 768 as if the original image was not rotated before the resizing, and to add to this I get a landscape image of 1036x768 with a right white vertical stripe and the bottom part cropped out. I tried by moving around the -resize and -auto-orient in various position before and after the input file in the command line, but always with different wrong results.

I can reach the goal by analyzing the orientation beforehand, removing the -auto-orient and setting the -resize to x768 instead of 768x, but this work should be done automatically by the -auto-orient option, not by me. Also the handling should be different depending on the orientation metadata inside the image file.

Am I doing anything wrong in the command line or is it a real bug?

Images

This is the original image:
mirrored_and_rotated_270_CW-original

This the resized one:
mirrored_and_rotated_270_CW-resized_768x

@snibgo
Copy link

snibgo commented Apr 30, 2024

You have IM v7, but use the convert command, which uses the old v6 syntax. One problem with the v6 syntax is that operations were not necessarily executed in the order you specify.

You rely on v6 doing operations out of order, because you have "-antialias -background 'white' -flatten -auto-orient" before reading the input. With v7 syntax, this is not permitted: we can't -flatten or -auto-orient an image before we have read the image.

Instead, I suggest using the magick command. This will execute operations in the order you specify.

This works fine for me, with IM v7.1.1-20, where topLeftIn.jpg is your input file:

magick topLeftIn.jpg -antialias -background white -flatten -auto-orient -resize 768x out.png

@mcu70
Copy link
Author

mcu70 commented Apr 30, 2024

It works, thanks! I have to check all my syntax now.

@mcu70 mcu70 closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants