Page 1 of 1

Rotate using script

Posted: 2016-12-13T07:31:55-07:00
by PaulLee
Hi,
I'm using ImageMagick on Linux (version 6.8.9-9) and I'd like to rotate a transparent gif in a directory through angles varying from -90 to +90 degrees. I'd like to invoke a shell script and then save each converted image with the angle appended (eg MyImage90.gif and MyImage-60.gif). My knowledge of bash etc is not very good - can anyone help?

Best wishes

Paul

Re: Rotate using script

Posted: 2016-12-13T09:59:00-07:00
by fmw42
Are these animated gifs or single frame gifs? What increments of angle?

Re: Rotate using script

Posted: 2016-12-13T10:03:23-07:00
by fmw42
try

Code: Select all

infile="MyImage.gif "
incr=30
inname=`convert "$infile" -format "%t" info:`
for ((i=-90; i<=90; i=i+incr)); do
convert "$infile" -background none -rotate $i ${inname}$i.gif
done

Re: Rotate using script

Posted: 2016-12-13T10:21:59-07:00
by GeeMack
PaulLee wrote:I'm using ImageMagick on Linux (version 6.8.9-9) and I'd like to rotate a transparent gif in a directory through angles varying from -90 to +90 degrees. I'd like to invoke a shell script and then save each converted image with the angle appended (eg MyImage90.gif and MyImage-60.gif). My knowledge of bash etc is not very good - can anyone help?
If I understand what you're trying to accomplish, it may be possible with a single IM command. Here's an example using IM 6.9.6 in a Windows command shell. With a simple conversion to a *nix command, this should get you pretty close...

Code: Select all

convert input.gif -rotate -90 -duplicate 179 ^
   -distort SRT %[fx:t] -set filename:f MyImage%[fx:t-89] +adjoin %[filename:f].gif
To work on a *nix shell you'd have to change that continued line character from a caret "^" to a backslash "\", or just don't make it a multi-line command. I can't try this on a *nix shell right now, so there might be other issues with escaping or quoting special characters.

You might want to use a "-virtual-pixel" setting to manage the parts of the image that start outside the viewport and get moved in with the rotation.

Also, if you're starting with a multi-layer (animated) GIF, you'll have to "-flatten" the image right after reading it in, or maybe select which particular layer you want to work with by specifying its index like "input.gif[0]".