GD Text-Gradient

WAHOO I am officially awesome :cool:

/* Create and save the gradiant */
$Imagick = new Imagick();
$Imagick->newPseudoImage( 500, 100, "gradient:red-orange" );
$Imagick->setImageFormat( 'png' );
$Imagick->writeImage("gradiant.png");

/* Create and save the canvas */
$im = new Imagick();
$im->newPseudoImage( 500, 100, "null:" );
$im->setImageFormat( 'png' );
$im->writeImage("canvas.png");

/* Add the text to the canvas ( Make the mask )*/
$im = new Imagick( "canvas.png" ); 
$draw = new ImagickDraw();
$draw->setFontSize( 90 ); 
$draw->setFillColor( new ImagickPixel("black"));

// Set gravity to the center.
$draw->setGravity( Imagick::GRAVITY_CENTER ); 
 
// Write the text on the image 
$im->annotateImage( $draw, 0, 0, 0, "Anthony" );

/* Final image */
$canvas = new Imagick( "gradiant.png" ); 
$canvas->compositeImage( $im, imagick::COMPOSITE_DSTIN, 0, 0 );
$canvas->setImageFormat( 'png' );
$canvas->writeImage("final.png");

unlink("canvas.png");
unlink("gradiant.png");
?>

This works and should give someone a starting point BUT some settings may be wrong for your version of Imagick AND in my case setFont() had no effect !
I am sure I have some more faults in the code though and I could not have done it without the example sites linked in my previous post.

1 Like