From: Tony Cook Date: Sun, 24 Oct 2010 01:18:42 +0000 (+0000) Subject: add wiggle.pl sample X-Git-Tag: Imager-0.79~19 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/b5c0ab7fe7b11e65ce07ebfaeb123b11799e6aed?ds=inline add wiggle.pl sample --- diff --git a/Changes b/Changes index c63250ca..a1adfa98 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ Imager 0.79 - unreleased This significantly speeds up presets like "addalpha", "green". https://rt.cpan.org/Ticket/Display.html?id=51254 + - add wiggle.pl sample, as suggested by Dan Oppenheim. + Bug fixes: - treat the co-efficients for convert() as doubles instead of floats. diff --git a/samples/README b/samples/README index a45f37af..77f3886c 100644 --- a/samples/README +++ b/samples/README @@ -116,3 +116,9 @@ quad_to_square.pl Sample from Richard Fairhurst demonstrating the use of the transform2() det() function. Transforms an arbitrary quadrilateral in the input into a square on the output. + +wiggle.pl + + Produce an animated GIF that blends back and forth between the two + supplied images. If the input images form a stereo pair the GIF can + be used for wiggle stereoscopy. diff --git a/samples/wiggle.pl b/samples/wiggle.pl new file mode 100644 index 00000000..1b7d0140 --- /dev/null +++ b/samples/wiggle.pl @@ -0,0 +1,68 @@ +#!perl -w +use strict; +use Imager; + +my $left_name = shift; +my $right_name = shift; +my $out_name = shift + or die "Usage: $0 left right out\n"; + +my $left = Imager->new(file => $left_name) + or die "Cannot read $left_name: ", Imager->errstr, "\n"; + +my $right = Imager->new(file => $right_name) + or die "Cannot read $right_name: ", Imager->errstr, "\n"; + +$left = $left->scale; +$right = $right->scale; + +my $steps = 5; + +my @cycle; + +push @cycle, $left; +my @down; +my @delays = ( 50, ( 10 ) x ($steps-1), 50, ( 10 ) x ($steps-1) ); + +for my $pos (1 .. $steps-1) { + my $work = $left->copy; + $work->compose(src => $right, opacity => $pos/$steps); + push @cycle, $work; + unshift @down, $work; +} +push @cycle, $right, @down; + + +Imager->write_multi({ file => $out_name, gif_delay => \@delays, gif_loop => 0, make_colors => "mediancut", translate => "errdiff" }, @cycle) + or die "Cannot write $out_name: ", Imager->errstr, "\n"; + +=head1 NAME + +wiggle.pl - wiggle stereoscopy + +=head1 SYNOPSIS + + perl wiggle.pl left.jpg right.jpg out.gif + +=head1 DESCRIPTION + +Produces an animated GIF that displays left, then a blend of four +images leading to right then back again. The left and right images +are displayed a little longer. + +If the left and right images form a stereo pair (and the order doesn't +really matter) the output animated GIF is useful for wiggle +stereoscopy. + +=head1 CREDITS + +Dan Oppenheim described the effect and asked +how to implement it. + +=head1 AUTHOR + +Tony Cook + +=cut + +