#!/usr/local/bin/perl -w # Example 3-4. use strict; use Image::Magick; # The width of the frame is determined by $framew and # the number of frames to produce is given by $frames my ($filename, $status) ; my $framew = 100; my $frames = 10; unless (defined($filename = $ARGV[0])) { die "Usage: perl example3-4.pl filename\n"; } my $image = new Image::Magick; # composite source file my $tempimage = new Image::Magick; # used later as a temp image my $imageout = new Image::Magick; # final output image $status = $image->Read("$filename"); if ($status) { die "$status"; } my ($width, $height) = $image->Get('width', 'height'); # The increment of each scene shift (in pixels) is given by $increment. # A smaller increment produces smoother action and larger files. my $increment = 15; print STDERR "Creating scenes...\n"; my $count = -1; # We use Image::Magick's Roll() and Crop() functions # to shift the image with each frame and crop to an appropriate size. my ($rollgeometry, $cropgeometry); for (my $x=0; $x < $width; $x+=$increment) { # Set up the geometry strings for the next roll and crop $rollgeometry = $framew."x$height+$x+0"; $cropgeometry = $framew."x$height"; # The Clone() method copies the content of $images # into the temporary image. $tempimage = $image->Clone(); $count++; $tempimage->Roll($rollgeometry); # Roll it $tempimage->Crop($cropgeometry); # Crop it # Now copy the area to the next frame of the output image. $imageout->[$count] = $tempimage->Clone(); undef $tempimage; # Clean up } $imageout->Set(loop=>0); # Set infinite loop print STDERR "Writing file...\n"; $imageout->Write("gif:scrolling$filename");