Command example to create animated wave...

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

Command example to create animated wave...

Post by GeeMack »

This isn't a question or problem, for a change. :) I just thought I'd share this fairly simple effect I worked out with IM7. It turns any image into an animated GIF with a ripple effect like a flag waving. Here's an example of the output...

Image

The command here is in Windows command line syntax...

Code: Select all

magick input.jpg ^
   -background none ^
   -set filename:f "%[t]" ^
   -resize %[fx:w-(w%10)]x ^
   -dither floydsteinberg ^
   -duplicate 9 ^
   -virtual-pixel tile ^
   -distort affine "0,0 -%[fx:t*(w*0.05)],0" ^
   -wave %[fx:min(w,h)*0.01]x%[fx:w*0.5] ^
   -distort affine "0,0 %[fx:t*(w*0.05)],0" ^
   -set dispose background ^
   -set delay 15 ^
   -loop 0 ^
      "%[filename:f]_wavy.gif"
The command takes any image as input, resizes it to the next smaller width divisible by 10, and creates a stack of ten copies. Then it uses "-distort affine" to shift each image in the stack to the left by 5% more than the last. The "-distort" operation relies on "-virtual-pixel tile" to make it act like "-roll".

After all the images in the stack are shifted incrementally, a "-wave" effect is added, then they're all un-shifted back to their original locations. The result is each image in the stack has a wave a little further along than the last. Finish up by setting a delay and output the stack to a GIF named by using the filename of the input image.

Here's another example...

Image

The movement is pretty smooth for only using a stack of ten images, and the output file sizes are relatively small for the amount of visible movement in the animation. More detail in the input image will mean a larger file of course, but a simple image like the flag at the top is under 100k.

To use this in a Windows BAT script would require changing all the single percent signs "%" to doubles "%%". To use it in a *nix shell it requires escaping all the parentheses with backslashes "\", changing all the double quotes to single quotes, and changing all the continued line carets "^" into backslashes "\".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Command example to create animated wave...

Post by snibgo »

Ha! Cute.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command example to create animated wave...

Post by fmw42 »

Very clever!
Post Reply