Fill patterns 'Imagick' : Create and modify images : Graphics Image PHP Source Code


PHP Source Code » Graphics Image » Create and modify images »

 

Fill patterns 'Imagick'


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->compositeImagick::COMPOSITE_OVER005050$im );
/* Close the pattern */
$draw->popPattern();
/* Use the pattern called "ice" as the fill */
$draw->setFillPatternURL'#ice' );
/* Set font size to 52 */
$draw->setFontSize52 );
/* Annotate some text */
$draw->annotation550"Hello World!" );
/* Create a new canvas and white image */
$canvas = new Imagick();
$canvas->newImage31070"white" );
/* Add black border around the resulting image */
$canvas->borderImage'black'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;
?>




HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Graphics Image
» Create and modify images