Page 1 of 1

Problem with appendimages()

Posted: 2011-04-07T20:44:49-07:00
by DJ Mike
The code at the bottom of this post was used to create this image:

Image

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);
  }
 
Entire script:

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>

Re: Problem with appendimages()

Posted: 2011-04-07T20:59:55-07:00
by fmw42
Don't know that I can help. But pretty impressive animation!

How about creating an oval gradient and applying a rainbow to that and rotating the colors in the gradient so that it radiates outward or inward and using your text as a mask over the oval gradient to color the text? Just a thought about an approach. I have not tested it or given it much thought.

But see the concept some what similar in my pseudocolor script below

Re: Problem with appendimages()

Posted: 2011-04-08T11:25:56-07:00
by DJ Mike
Thanks. That is a very different approach that never occurred to me. I never got used to command line syntax so it'll take me a while to test it. It might fix another problem I had. A earlier version would make a swirly with a transparent background:

Image

On the latest version I could make the form with a check box the transparent BG and it work for ellipses but sometimes the colors are blotchy. If you pick some combination of options the gradient gets resized twice and some pixels are lost and become transparent.