All pastes #792316 Raw Edit

GifCATCHA

public php v1 · immutable
·published 2007-11-21 09:02 UTC
rendered paste body
<?php/*** Creates a GIF images of a string being typed * $string is the string that will be displayed (No line breakes)* $delay is the time the before another character is typed* $finaldelay is the time that the whole string should be displayed in the end before redrawing* $output is the file that should be outputted to if let empty the image is outputted directly*//** Use<?phpGifCATCHA('Hello World',30,60,'myfile.gif);?>function GifCATCHA($string,$delay,$finaldelay,$output=false) {	/* This object will hold the animation */	$animation = new Imagick(); 	/* Set the format to gif. All created images will be gifs*/	$animation->setFormat( "gif" ); 	/* Create a pixel to handle colors */	$color = new ImagickPixel( "white" ); 	/* The first frame */	$color->setColor( "white" );  	/* Create a new ImagickDraw object and set the font	    Text color defaults to black */	$draw = new ImagickDraw(); 	/* You can get configured fonts with $im->queryFonts 	    or use /path/to/file.ttf */	$draw->setFont( "Helvetica" ); 	/* Loop trough the string.. */	for ( $i = 0; $i <= strlen( $string ); $i++ )	{	    /* Take some characters for this frame */	    $part = substr( $string, 0, $i );	 	    /* Create a new frame */	    $animation->newImage( 100, 50, $color );	    	    /* Annotate the characters on the image */	    $animation->annotateImage( $draw, 10, 10, 0, $part );	 	    /* Set a little higher delay for the frame*/	    $animation->setImageDelay($delay);	} /* The last frame contains the same text with bold */$draw->setFont( "Helvetica" ); /* One more frame */$animation->newImage( 100, 50, $color ); /* Annotate the bold text on the image */$animation->annotateImage( $draw, 10, 10, 0, $string ); /* The bold can be visible a little longer time */$animation->setImageDelay($finaldelay); if($output) {	file_put_contents($output,$animation->getImagesBlob(),'w+');} else {	/* Display the output as an animation. 		Use getImagesBlob to get all images combined */	header( "Content-Type: image/gif" );	echo $animation->getImagesBlob();}}?>