How to make an easy-to-use script/file which finds and rotates horizontal images on Windows 7?

2

1

If I have a folder with hundreds of images, and some are wider than they are tall, I'd like to be able to easily rotate the wide images so everything is vertical. Currently I have to skim through the thumbnails and manually flip all the horizontal images.

I've seen "shell scripts" and "imagemagick" mentioned in regards to this, but I can't figure out how I'm supposed to use these on Windows 7. How can I make something like a batch file which I can easily place in the folder and have it do everything for me?

barbiedolphin

Posted 2019-01-31T13:58:06.293

Reputation: 21

1Are your images jpeg, and are you trying to rotate them selectively to be correctly upright? – harrymc – 2019-01-31T15:03:16.603

Yes, they're JPEGs. If by "selectively" you mean selecting only the ones I want (the wider ones), then that's right. – barbiedolphin – 2019-01-31T15:06:43.697

Answers

2

Processing .jpg (rotating) can degrade them so best off starting with not overwriting.

Download Imagemagick for Windows

From a batch file. Do not overwrite originals. Rotate 90 degrees clockwise:

@echo off
SETLOCAL ENABLEEXTENSIONS
md "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\rotated\"
for /f "tokens=*" %%x in ('dir /b "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\*.jpg"') do "path-to-imagemagick\convert.exe" "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\%%x" -rotate "90>" "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\rotated\%%x"
exit /b

For example:

@echo off
SETLOCAL ENABLEEXTENSIONS
md "%USERPROFILE%\Desktop\New folder\rotated\"
for /f "tokens=*" %%x in ('dir /b "%USERPROFILE%\desktop\new folder\*.jpg"') do "%ProgramFiles%\ImageMagick-7.0.7-Q16\convert.exe" "%USERPROFILE%\desktop\new folder\%%x" -rotate "90>" "%USERPROFILE%\desktop\new folder\rotated\%%x"
exit /b 

From a batch file. Overwrite originals. Rotate 90 degrees clockwise:

@echo off
SETLOCAL ENABLEEXTENSIONS
for /f "tokens=*" %%x in ('dir /b "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\*.jpg"') do "path-to-imagemagick\convert.exe" "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\%%x" -rotate "90>" "path-to-parent-folder-with-double-quotes-if-there-is-a-space-in-the-path\%%x"
exit /b 

For example:

@echo off
SETLOCAL ENABLEEXTENSIONS
for /f "tokens=*" %%x in ('dir /b "%USERPROFILE%\desktop\new folder\*.jpg"') do "%ProgramFiles%\ImageMagick-7.0.7-Q16\convert.exe" "%USERPROFILE%\desktop\new folder\%%x" -rotate "90>" "%USERPROFILE%\desktop\new folder\rotated\%%x"
exit /b 

A windows shortcut that rotates 90 degrees clockwise and overwrites every .jpg in the directory it is started in:

   cmd /c for /f "tokens=*" %x in ('dir /b *.jpg') do "%ProgramFiles%\ImageMagick-7.0.7-Q16\convert.exe" "%x" -rotate "90>" "%x"

A windows shortcut that rotates 90 degrees clockwise and overwrites every .jpg in the directory it is started in and in all the subdirectories:

   cmd /c for /f "tokens=*" %x in ('dir /b /s *.jpg') do "%ProgramFiles%\ImageMagick-7.0.7-Q16\convert.exe" "%x" -rotate "90>" "%x"

Start in:

rotate 90 degress clockwise

-rotate "90>"

rotate 90 degress counterclockwise

-rotate "-90>"

Apply Path image rotation (using shear operations) to the image. Use > to rotate the image only if its width exceeds the height. < rotates the image only if its width is less than the height. For example, if you specify -rotate "-90>" and the image size is 480x640, the image is not rotated. However, if the image is 640x480, it is rotated by -90 degrees. If you use > or <, enclose it in quotation marks to prevent it from being misinterpreted as a file redirection. Empty triangles in the corners, left over from rotating the image, are filled with the background color. The above is from here.

See also the -distort operator and specifically the 'ScaleRotateTranslate' distort method.

For more info about using imagemagick command line processing see here

somebadhat

Posted 2019-01-31T13:58:06.293

Reputation: 607