Animated glowing text banner with PHP

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
DJ Mike
Posts: 33
Joined: 2010-06-29T19:07:53-07:00
Authentication code: 8675308

Animated glowing text banner with PHP

Post by DJ Mike »

http://eclecticdjs.com/mike/temp/10/06/ ... d_glow.php

Code: Select all

<?
$text = "DJ Mike";
$font = "lokicola.ttf";
$fontsize = 100;
#$fontcolor = "#aa0000";
$fontcolor = "#ffff88";
$file = "banner.gif";

$glow_radius = 3;
# Three glow colors
$glow = array( "#ff0000", "#ff8800", "#ffff00" );
$delay = 15;
# moves text down
$offset = 12;

# make a black pallete
$pallete = new Imagick;
$pallete->newimage(375,140, "#000000");
# set pallet format to gif
$pallete->setimageformat("gif");

# make a draw object with settings
$draw = new imagickdraw();
$draw->setgravity(imagick::GRAVITY_CENTER);
$draw->setfont("$font");
$draw->setfontsize($fontsize);

# clone pallete to make 3 blank frames
$frame_0 = $pallete->clone();
$frame_1 = $pallete->clone();
$frame_2 = $pallete->clone();

# put them in an array
$frames = array($frame_0, $frame_1, $frame_2);

# loop through frames, double glow radius each time, annotate
foreach( $frames as $frame)
 {
  # Loop through glow colors, annotate and blur
  foreach( $glow as $color)
  {
   $draw->setfillcolor("$color");
   $frame->annotateImage ( $draw,0 ,$offset, 0, $text );
   $frame->annotateImage ( $draw,0 ,$offset, 0, $text );
   $frame->BlurImage( $glow_radius, $glow_radius ); 
  }
 # top layer of text over glow
 $draw->setfillcolor("$fontcolor");
 # center annotate on top of offset annotates
 $frame->annotateImage ( $draw,0 ,$offset, 0, $text );
 # double glow radius for next loop
 $glow_radius = $glow_radius*2;
 }

# add frames
$frame_0->addImage($frame_1);
$frame_0->addImage($frame_2);

# slow it down a little
$frame_0->setImageDelay("$delay");

# write frames
$frame_0->writeimages( "$file", FALSE);
# write animation
$frame_0->writeimages( "$file", TRUE);
# send some HTML to the browser to show the results
?>
<html>
<body bgcolor="black" text="white">
Animated<br>
<img src="banner.gif"><hr>
Frames<br>
<img src="banner-0.gif"><br>
<img src="banner-1.gif"><br>
<img src="banner-2.gif">

</body>
</html>
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
byron
Posts: 9
Joined: 2010-05-07T05:07:56-07:00
Authentication code: 8675308

Re: Animated glowing text banner with PHP

Post by byron »

Nice work!
Post Reply