LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   any batch command to rotate many photos at once? (https://www.linuxquestions.org/questions/linux-general-1/any-batch-command-to-rotate-many-photos-at-once-4175678252/)

newbiesforever 07-06-2020 01:35 PM

any batch command to rotate many photos at once?
 
I took a large number of photos on a trip; many are dupes that I will delete, but as it is, I have over 130 at the moment. Most or all of them are sideways. Is there any command that would save me some time by rotating them all in a batch to the desired position?

michaelk 07-06-2020 01:42 PM

Imagemagick's convert command. Would be easy to write a bash script.

Check out mogrify too.

pan64 07-06-2020 01:50 PM

just curious: Usually I process all the images one by one, so rotating is not an issue, because I check every and each picture taken. By the way, the software I use knows the original orientation, so the pictures are adjusted by default. This problem only occurred when non-official tools were used.

ondoho 07-06-2020 02:58 PM

Quote:

Originally Posted by pan64 (Post 6142270)
the software I use knows the original orientation, so the pictures are adjusted by default. This problem only occurred when non-official tools were used.

Important point, though I wouldn't have used the term "non-official" here.
Your image viewer might not be aware of exif rotation data.
It depends on what you do with these pictures in the end, but it might not be necessary to do anything at all.

KGIII 07-06-2020 06:00 PM

If you want a GUI, non-opensource, option to rotate a bunch of images at once, there's XNViewMP (available in 32/64 bit for Linux) and it has a "Batch Convert." In the actions section of the batch convert you can choose to rotate the images (among many other things).

It's free for personal use, but not opensource. I like it, mostly because I'm used to the workflow and know where everything is. It has been around forever and I was *really* grateful when they made it into a Linux app.

rnturn 07-12-2020 04:58 PM

Quote:

Originally Posted by pan64 (Post 6142270)
just curious: Usually I process all the images one by one, so rotating is not an issue, because I check every and each picture taken. By the way, the software I use knows the original orientation, so the pictures are adjusted by default. This problem only occurred when non-official tools were used.

You could look at the aspect ratio of the images with identify(1) and decide whether they need to be rotated. Not a guarantee that would work in all cases---I tend to do portrait shots of people and landscape shot of, well, landscapes and would not want people or nature arbitrarily rotated.

Fire up a file manager and examine and move (or copy, for the more paranoid of us) all the photos that need to be rotated into a temporary subdirectory, and turn a script loose on those that require rotation in that subdirectory. I might even rename those to something like "img_1234.rotated.jpg" after rotation and before moving them back into the original directory to preserve the original, un-rotated images.

dugan 07-12-2020 05:28 PM

Do you want to reorder the pixels, or do you want to change the EXIF information?

Skaperen 07-12-2020 07:58 PM

create 2 directories called "notrotated" and "rotated". copy all the image files that need to be rotated into "notrotated". once you know what option for the convert commant will rotate them for you, you can run a command like this:
Code:

(ls -1 notrotated|while read n;do ls -l "notrotated/$n";convert put_options_here "notrotated/$n" "rotated/$n";ls -l "rotated/$n";done)
then you will have the rotated ones in the "rotated" directory with the same name. do not do this directly on your only copy of files, just in case.

i do bash commands like this a few times every day.

EdGr 07-12-2020 10:03 PM

jpegtran can rotate JPEG images with no loss of image quality.

Code:

for n in *.JPG; do jpegtran -rotate 90 $n >$n-rotate.jpg; done
Ed

ondoho 07-16-2020 03:41 AM

Quote:

Originally Posted by EdGr (Post 6144768)
jpegtran can rotate JPEG images with no loss of image quality.

Not always, unfortunately:
Quote:

Originally Posted by jpegtran
-perfect Fail if there is non-transformable edge blocks

I had to find out the hard way.

TenTenths 07-16-2020 08:25 AM

I've found that using -auto-orient with ImageMagic convert works nicely to sort out orientation on files. Of course this depends on whether your image source contains relevant orientation information.

EdGr 07-16-2020 09:28 PM

Quote:

Originally Posted by ondoho (Post 6146001)
Not always, unfortunately:
I had to find out the hard way.

There is something to be said about reading the manual. ;)

jpegtran should have worked on the OP's photos.
Ed


All times are GMT -5. The time now is 09:57 PM.