The example illustrates using an image as a part of a named fill pattern. The fill pattern is used to annotate text but the named pattern could also be used to fill any shapes that allow fill to be specified (include circles, ellipses, rectangles, polygons etc etc). The code itself is pretty straight forward: Read the image, create the pattern and use the pattern as a fill.
<?
// Create a new imagick object */
$im = new Imagick( 'iceformations5679.JPG' );
/* Create imagickdraw object */
$draw = new ImagickDraw();
/* Start a new pattern called "ice" */
$draw->pushPattern( 'ice' , 0 , 0 , 50 , 50 );
/* Composite the image on the pattern */
$draw->composite( Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im );
/* Close the pattern */
$draw->popPattern();
/* Use the pattern called "ice" as the fill */
$draw->setFillPatternURL( '#ice' );
/* Set font size to 52 */
$draw->setFontSize( 52 );
/* Annotate some text */
$draw->annotation( 5, 50, "Hello World!" );
/* Create a new canvas and white image */
$canvas = new Imagick();
$canvas->newImage( 310, 70, "white" );
/* Add black border around the resulting image */
$canvas->borderImage( 'black', 1, 1 );
/* Draw the ImagickDraw on to the canvas */
$canvas->drawImage( $draw );
/* Set the format to PNG */
$canvas->setImageFormat( 'png' );
/* Output the image */
header( "Content-Type: image/png" );
echo $canvas;
?>
|