Code: Select all
<?php
$file = "ani_circle_001.gif";
$w = 200;
$h = 100;
$delay = 10;
$deg = -360;
### First make a rainbow line
# new imagick object
$img1 = new Imagick();
# some gradients
$img1->newPseudoImage( 10, 100, 'gradient:red-orange' );
$img1->newPseudoImage( 10, 100, 'gradient:orange-yellow' );
$img1->newPseudoImage( 10, 100, 'gradient:yellow-green' );
$img1->newPseudoImage( 10, 100, 'gradient:green-blue' );
$img1->newPseudoImage( 10, 100, 'gradient:blue-purple' );
$img1->newPseudoImage( 10, 100, 'gradient:purple-red' );
# go back to top of stack
$img1->resetIterator();
$line = $img1->appendImages(true);
# rotate
$line->rotateImage(new ImagickPixel(), 270);
# resize
$line->scaleimage($w, $h, FALSE );
$line->setimagebackgroundcolor("transparent");
$line->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_BACKGROUND );
# Clone line, arc it, resize, swirl
$frame_0 = $line->clone();
$frame_0->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
$frame_0->scaleimage($w, $w, FALSE );
$frame_0->swirlimage($deg);
# Roll line 1/5th of width, clone, arc, swirl
$line->rollimage( $w/5, 0 );
$frame_1 = $line->clone();
$frame_1->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
$frame_1->scaleimage($w, $w, FALSE );
$frame_1->swirlimage($deg);
# Roll line 1/5th of width, clone, arc, swirl
$line->rollimage( $w/5, 0 );
$frame_2 = $line->clone();
$frame_2->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
$frame_2->scaleimage($w, $w, FALSE );
$frame_2->swirlimage($deg);
# Roll line 1/5th of width, clone, arc, swirl
$line->rollimage( $w/5, 0 );
$frame_3 = $line->clone();
$frame_3->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
$frame_3->scaleimage($w, $w, FALSE );
$frame_3->swirlimage($deg);
# Roll line 1/5th of width, clone, arc, swirl
$line->rollimage( $w/5, 0 );
$frame_4 = $line->clone();
$frame_4->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
$frame_4->scaleimage($w, $w, FALSE );
$frame_4->swirlimage($deg);
# new object to hold animation
#$ani = new Imagick();
# add frames
$ani = $frame_0->clone();
$ani->setImageDelay($delay);
$ani->addimage($frame_1);
$ani->setImageDelay($delay);
$ani->addimage($frame_2);
$ani->setImageDelay($delay);
$ani->addimage($frame_3);
$ani->setImageDelay($delay);
$ani->addimage($frame_4);
$ani->setImageDelay($delay);
# Write final image
$ani->writeimages( "$file", TRUE);
header( "location:$file" );
exit;
?>