Auto-rotate images based on their Exif data with ImageMagick



Published: 2020-01-08 11:34:24 +0000
Categories: BASH,

Language

BASH

Description

Most modern cameras will store orientation details in the EXIF data of images taken on them. So if you turn the camera portrait to take an image, software can tell that this image should be displayed portrait.

However, not all software checks the EXIF data first, so you can wind up with portrait images being displayed lying on their side in some software - this is an easy trap to fall into if your file manager does honour the EXIF data.

ImageMagick's convert command can be used to read in the EXIF data, check the orientation and then rotate the image if required.

Snippet

convert $IMAGE -auto-orient $IMAGE_OUTPUT

Usage Example

# Auto-rotate foo.jpg in place
convert foo.jpg -auto-orient foo.jpg

# Auto-Rotate all images within a directory in place
for i in `ls *JPG`; do convert "$i" -auto-orient "$i"; done

# Auto-Rotate all images but save into a subdir
mkdir op
for i in `ls *JPG`; do convert "$i" -auto-orient "op/$i"; done

Requires

Keywords

image, rotate, auto-orient, exif, imagemagick,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter