Rotate using script

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
PaulLee
Posts: 2
Joined: 2016-10-16T14:24:10-07:00
Authentication code: 1151

Rotate using script

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rotate using script

Post by fmw42 »

Are these animated gifs or single frame gifs? What increments of angle?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rotate using script

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

Re: Rotate using script

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