I have once seen a simple but interesting animation effect somewhere, but can't find that image anymore. So I decided to reproduce the effect myself, and wrote a script that given a static input image, produces an animated gif. I succeeded, and now I have that script, I'd like to share. However, Perlmonks doesn't allow embedding images, so I'll include here the source only, while the step-by-step tutorial with intermediate images and deeper explanations shall be accessible here:
Here's the source:
use strict; use Prima 1.27; use IPA qw(Misc); die "need image\n" unless @ARGV; my $source = Prima::Image-> load($ARGV[0]); die "Can't load $ARGV[0]:$@\n" unless $source; $source-> type(im::bpp24); my $mask = Prima::Image-> new( width => $source-> width * 2, height => $source-> height * 2, type => im::BW, ); my @size = $mask-> size; my $max = $size[$size[0] < $size[1]] / 2; my $step = 2; my @centers = ( [ 243, 159 ], [ 208, 150 ], [ 233, 111 ], ); my @img; for ( my $offset = 0; $offset < $step * 2; $offset++) { $mask-> begin_paint; $mask-> clear; $mask-> lineWidth( $step); my @center = map { int($_ + .5) } ($size[0] / 2, $size[1] / 2); for ( my $i = 0; $i < $max; $i += $step * 2) { my $d = $offset * 2 + $i * 2; $mask-> ellipse( @center, $d, $d); } $mask-> end_paint; my @channels = @{ IPA::Misc::split_channels( $source, 'rgb') }; for ( my $i = 0; $i < @channels; $i++) { $channels[$i]-> put_image( $centers[$i]->[0] - $center[0], $centers[$i]->[1] - $center[1], $mask, rop::AndPut ); } my $output = combine_channels( \@channels, 'rgb'); $output-> type(im::bpp8); push @img, $output; } my $saved = Prima::Image-> save( "output.gif", images => \@img, loopCount => 0, delayTime => 5, ); die "Cannot save output.gif:$@\n" unless $saved == @img;
Comments and suggestions are welcome.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Image manipulation with Prima
by zentara (Cardinal) on Nov 10, 2008 at 20:18 UTC | |
by dk (Chaplain) on Nov 10, 2008 at 23:47 UTC | |
|
Re: Image manipulation with Prima
by wol (Hermit) on Nov 11, 2008 at 17:35 UTC | |
|
Re: Image manipulation with Prima
by pmonk4ever (Friar) on Nov 12, 2008 at 19:33 UTC |