Page 1 of 1
How to stop auto rotate
Posted: Wed May 31, 2023 9:40 pm
by MitchellFerguson
When I use nconvert it rotates images after converting them
Looked through the -help but didn't see anything that looked like it would do what I needed and search only turned this up
viewtopic.php?f=57&t=38239&p=153383&hil ... te#p153383 Thanks in advance for any help

Re: How to stop auto rotate
Posted: Thu Jun 01, 2023 9:27 am
by xnview
please use -no_auto_rotate
Re: How to stop auto rotate
Posted: Thu Jun 01, 2023 5:18 pm
by MitchellFerguson
xnview wrote: Thu Jun 01, 2023 9:27 am
please use -no_auto_rotate
secret options!
Thanks
Edit:
I got an error, Bad Argument -'no_auto_rotate'
Edit2:
Changed it from (this causes the error)
Code: Select all
nconvert -no_auto_rotate -out tiff
to
Code: Select all
nconvert -out tiff -no_auto_rotate
and it runs but still rotates the image.
Re: How to stop auto rotate
Posted: Fri Jun 02, 2023 8:06 am
by xnview
which version do you use? It works with latest version
Re: How to stop auto rotate
Posted: Fri Jun 02, 2023 9:06 am
by MitchellFerguson
xnview wrote: Fri Jun 02, 2023 8:06 am
which version do you use? It works with latest version
I did some more testing and it works fine for images I found online but images I've taken seem to be the problem

It's weird, exiftool seems to cause the same behavior. I thought if I stripped the file of all the metadata it would behave but it rotated the image as well using
but then I went to convert it using nconvert and it didn't rotate it.
Re: How to stop auto rotate
Posted: Sat Jun 03, 2023 6:08 am
by xnview
could you post an image file
Re: How to stop auto rotate
Posted: Sat Jun 03, 2023 10:14 am
by MitchellFerguson
I
think I understand the problem now

These pictures were taken with my phone and apparently holding your phone sideways results in your photos being taken correctly and holding your phone straight up and down results in them being rotated but software doesn't reflect this for some reason.
I took two example photos to test, this fuse I photographed holding the phone vertically.
It displays as I took it but you can see in the bottom right of the image the orientation is seen as rotated 90 degrees. If I convert it to some other format like tiff then I assume nconvert just reads the orientation information and outputs it that way.
though one curious thing is that once it is converted that Orientation tag isn't present in the program I'm using (Picasa) anymore
(rotated after nconverted to tiff)
The pen image was taken horizontally and has an orientation tag of "Normal"
When converted to tiff it retains its orientation
I tried to attach them but got an error "Sorry, the board attachment quota has been reached."
https://www.mediafire.com/file/eqfzoqca ... s.zip/file
Re: How to stop auto rotate
Posted: Sun Jun 11, 2023 11:00 pm
by MitchellFerguson
I enlisted the help of ChatGPT to solve the problem

If anyone finds themselves in the same boat. Test on copies first. Python code.
Code: Select all
from PIL import Image
import os
def get_image_orientation(image_path):
# Open the image file
with Image.open(image_path) as img:
try:
# Get the EXIF information
exif = img._getexif()
if exif is not None:
# Check for the orientation tag (tag number 0x0112)
if 0x0112 in exif:
orientation = exif[0x0112]
# Rotate the image based on the orientation
if orientation == 3:
img = img.rotate(180, expand=True)
elif orientation == 6:
img = img.rotate(270, expand=True)
elif orientation == 8:
img = img.rotate(90, expand=True)
# Update the EXIF information with the new orientation
img = img._getexif()
img[0x0112] = 1
# Save the rotated image
img.save(image_path)
return "Normal"
except AttributeError:
pass
# If orientation information is not available or invalid, return None
return None
def scan_directory(directory_path):
# Iterate over all files in the directory
for filename in os.listdir(directory_path):
file_path = os.path.join(directory_path, filename)
# Check if the file is an image
if os.path.isfile(file_path) and is_image_file(filename):
# Check the image orientation
orientation = get_image_orientation(file_path)
if orientation is None:
continue #print(f"{filename}: not rotated (orientation information not available)")
elif orientation == "Normal":
continue #print(f"{filename}: not rotated")
else:
print(f"{filename}: rotated")
def is_image_file(filename):
# Check if the file extension corresponds to an image format
image_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp"]
return any(filename.lower().endswith(ext) for ext in image_extensions)
# Provide the path to the directory you want to scan
directory_path = "path/to/directory"
scan_directory(directory_path)