Rotate only bottom half of the images (batch)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dcd722
Posts: 1
Joined: 2016-09-26T06:31:18-07:00
Authentication code: 1151

Rotate only bottom half of the images (batch)

Post 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
Last edited by dcd722 on 2016-09-26T07:44:18-07:00, edited 3 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

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

Post 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".
Post Reply