Hello monks,

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:

Hypnotic effect

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.


In reply to Image manipulation with Prima by dk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.