My work life has been quite busy lately and I haven’t had a chance to sit down and blog. I have been touring around London and some parts of the northern England consulting and organizing some training here and there. Luckily I have had the chance to do some work on Imagick and the 2.2.0 beta release is getting closer. The internal structure was completely restructured and broken down into several smaller files. During this time Imagick was adapted to follow the PHP Coding Standards more closely. Still a work in progress :)

I committed slightly modified version of this example to PHP Manual http://uk.php.net/manual/en/imagick.examples.php page a few days ago. 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.

The ice formations image is from http://www.photoeverywhere.co.uk/west/winterholiday/slides/iceformations5679.htm.

  1. <?php
  2.  
  3. /* Create a new imagick object */
  4. $im = new Imagick( 'iceformations5679.JPG' );
  5.  
  6. /* Create imagickdraw object */
  7. $draw = new ImagickDraw();
  8.  
  9. /* Start a new pattern called "ice" */
  10. $draw->pushPattern( 'ice'  , 0  , 0  , 50  , 50 );
  11.  
  12. /* Composite the image on the pattern */
  13. $draw->composite( Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im );
  14.  
  15. /* Close the pattern */
  16. $draw->popPattern();
  17.  
  18. /* Use the pattern called "ice" as the fill */
  19. $draw->setFillPatternURL( '#ice' );
  20.  
  21. /* Set font size to 52 */
  22. $draw->setFontSize( 52 );
  23.  
  24. /* Annotate some text */
  25. $draw->annotation( 5, 50, "Hello World!" );
  26.  
  27. /* Create a new canvas and white image */
  28. $canvas = new Imagick();
  29. $canvas->newImage( 310, 70, "white" );
  30.  
  31. /* Add black border around the resulting image */
  32. $canvas->borderImage( 'black', 1, 1 );
  33.  
  34. /* Draw the ImagickDraw on to the canvas */
  35. $canvas->drawImage( $draw );
  36.  
  37. /* Set the format to PNG */
  38. $canvas->setImageFormat( 'png' );
  39.  
  40. /* Output the image */
  41. header( "Content-Type: image/png" );
  42. echo $canvas;
  43. ?>

And the result is here: