Page 1 of 1

Rotate only bottom half of the images (batch)

Posted: 2016-09-26T06:39:31-07:00
by dcd722
Hey,

I've recently scanned in a bunch of old photos. The method in which I've scanned them has the front of the photo on the top and the back of the photo at the bottom. I've got about 2000 photos that are like this.

The scanner when scanning front and back will only produce the image as a mirror (the 'back' of the photo is upside-down). In addition, all the scans are different heights and lengths - some off by just a few pixels, but others are much different due to different photo size.

I'd like to take all images in the folder, and rotate the bottom half (height/2) by 180 degrees



Win 10x64 -7.0.3-1

Re: Rotate only bottom half of the images (batch)

Posted: 2016-09-26T07:03:00-07:00
by snibgo
Please, everyone, when asking questions always state the version of IM you are using and your platform (bash, Windows or whatever).

This is for v6, on Windows, a console command:

Code: Select all

convert 5BsxN2a.jpg -crop 1x2@ +repage ( -clone 1 -rotate 180 ) -delete 1 -append outdir\out.png
That does one image. To do all the images in a directory, I would use a shell loop. In Windows:

Code: Select all

for %F in (*.jpg) do convert %F -crop 1x2@ +repage ( -clone 1 -rotate 180 ) -delete 1 -append outdir\%~nF.png

Re: Rotate only bottom half of the images (batch)

Posted: 2016-09-26T08:59:34-07:00
by GeeMack
snibgo wrote:To do all the images in a directory, I would use a shell loop. In Windows:

Code: Select all

for %F in (*.jpg) do convert %F -crop 1x2@ +repage ( -clone 1 -rotate 180 ) -delete 1 -append outdir\%~nF.png
Another approach, given enough memory on the machine, would be to read in the whole directory of JPGs, make a stack of clones, rotate those clones on a point centered at half the width and three-quarters of the height, then composite those clones over the originals. With IM6 "convert" or IM7 "magick" at a Windows 10 command prompt this does the job...

Code: Select all

magick *.jpg ^
   -set filename:f "%[t]" -background none -virtual-pixel none ^
   null: ^
   ( -clone 0--1 -distort SRT "%[fx:w*0.5],%[fx:h*0.75] 180" ) ^
   -layers composite "_fixed_%[filename:f].jpg"
That rotation is centered in the lower half of the image. It swings the upper half 180 degrees around and out of the frame leaving that lower half in its same place but upside-down — or right side up in this case. It requires a transparent background and a virtual-pixel setting of "none".