I wanted to have another option besides swirl: Reflect. Reflect would take each frame, flop it and append it to the original so the colors would radiate from the center instead of go in one direction. I used append to create the gradients but couldn't get it to work on each frame of the animation. Here is what I expected to work:
Code: Select all
foreach ($frames as $temp)
{
$flop = $temp->clone();
$flop->flopImage();
$temp->addimage($flop);
$temp->appendImages(false);
}
Code: Select all
<?php
$file = "logo.gif";
$font = "LOKICOLA.TTF";
if ( $_GET )
{
$w = $_GET[w];
$h = $_GET[h];
$f = $_GET[f]; # number of frames
$delay = $_GET[del];
if ($f < 1)
{ $move = 0;
$f = 1;
}
else
{ $move = $w/$f; }
# new imagick object
$img = new Imagick();
# remove NULL's from colors
foreach ($_GET[c] as $temp )
{
if ( strlen($temp) > 0 )
{ $colors[] = $temp; }
}
# how many colors?
$n = count($colors);
# make gradients till next to last color
for ($x=0; $x<$n-1; $x++)
{
$next = $x+1;
$gradient = "gradient:$colors[$x]-$colors[$next]";
$img->newPseudoImage( 100, 100, "$gradient" );
}
# loop last color back to first color
$last = $n-1;
$gradient = "gradient:$colors[$last]-$colors[0]";
$img->newPseudoImage( 100, 100, "$gradient" );
# go back to top of stack and append
$img->resetIterator();
$bar = $img->appendImages(true);
# rotate & resize
$bar->rotateImage(new ImagickPixel(), 270);
# $bar->scaleimage($w, $h, FALSE );
# new object for frames
$frames = new Imagick();
for ($x=0; $x<$f; $x++)
{
# roll, resize and add to frames
$bar->rollimage( $move, 0 );
$bar->scaleimage($w, $h, FALSE );
$frames->addimage($bar);
$frames->setImageDelay("$delay");
}
if ($_GET[swirl] == "on")
{
$m = max( array($w,$h) );
foreach ($frames as $temp)
{
/*
if ($_GET[transbg] == "on")
{
$temp->setimagebackgroundcolor("transparent");
$temp->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_TRANSPARENT );
}
*/
$temp->scaleimage($m, $m, FALSE );
$temp->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
$temp->swirlimage( max(0,$_GET[deg]) );
$temp->scaleimage($w, $h, FALSE );
}
}
############################
if ($_GET[reverse] == "on")
{
foreach ($frames as $temp)
{
$orig = $temp->clone();
$flop = $temp->clone();
$flop->flopImage();
$orig->addimage($flop);
$orig->appendImages(false);
#$temp->destroy();
#$temp = new Imagick();
#$temp->addimage($orig);
}
}
############################
/*
############################
if ($_GET[reflect] == "on")
$reflection = new Imagick();
foreach ($frames as $temp)
{
{
$orig = $temp->clone();
$flop = $temp->clone();
# $temp->removeimage(); # debug
$orig = $temp->clone();
$flop->flopImage();
$reflection->addimage($orig);
$reflection->addimage($flop);
# $temp->destroy();
# $temp = new Imagick();
# $temp->addimage($orig);
# $temp->addimage($flop);
$reflection->appendImages(false);
$temp->setImageFormat('gif');
$flop->setImageFormat('gif');
$reflection->setImageFormat('gif');
#$new->setImageFormat('gif');
header( "Content-Type: image/gif" );
echo $reflection; exit;
}
#$reflection->resetIterator();
#$reflection->appendImages(true);
$reflection->writeimages( "$file", TRUE);
header( "location:$file" );
}
##############################
*/
##############################
if ($_GET[txt] == "on")
{
$logo = new Imagick();
foreach ($frames as $temp)
{
$logo->newimage($w,$h, "transparent");
$draw = new ImagickDraw();
$draw->setfont("$font"); # set font
$draw->setfillcolor("#0000ff");
$draw->setgravity(imagick::GRAVITY_CENTER);
$draw->setFontSize( 90 );
# annotate
#$draw->annotation( 0, 0, "$_GET[text_entered]" );
$logo->annotateImage ( $draw,0 ,0, 0, "$_GET[text_entered]" );
$logo->drawImage( $draw );
$logo->compositeImage( $temp, imagick::COMPOSITE_ATOP, 0,0 );
}
$logo->setImageFormat('gif');
$logo->writeimages( "$file", TRUE);
header( "location:$file" );
exit;
}
##############################
# set the image format to gif
$bar->setImageFormat('gif');
# Write final image
$frames->writeimages( "$file", TRUE);
header( "location:$file" );
exit;
}
?>
<html>
<body>
<form>
<input type="text" name="w" size="3" value="500"> Width<br>
<input type="text" name="h" size="3" value="100"> Height<br>
<input type="text" name="f" size="3" value="10"> Frames<br>
<input type="text" name="del" size="3" value="3"> Delay<br>
<!--
<input type="text" name="deg" size="3" value="100"> Degrees<br>
-->
Colors<br>
<input type="text" name="c[]" value="#ff0000"><br>
<input type="text" name="c[]" value="#ff8800"><br>
<input type="text" name="c[]" value="#ffff00"><br>
<input type="text" name="c[]" value=""><br>
<input type="text" name="c[]" value="#00ff00"><br>
<input type="text" name="c[]" value=""><br>
<input type="text" name="c[]" value="#00ffff"><br>
<input type="text" name="c[]" value="#0088ff"><br>
<input type="text" name="c[]" value="#0000ff"><br>
<input type="text" name="c[]" value="#8800ff"><br>
Options:<br>
<!-- <input type="checkbox" name="reverse"> Reverse<br> -->
<input type="checkbox" name="reflect"> Reflect<br>
<input type="checkbox" name="swirl"> Swirl <input type="text" size="3" name="deg"> Degrees
<!-- /
<input type="checkbox" name="transbg"> Transparent BG --><br>
<input type="checkbox" name="txt"> Text:<br>
<input type="text" name="text_entered" value="DJ Mike">
<input type="submit"><br>
</form>
</body>
</html>