Imagick « Mikko’s blog

Beaucoup de tutoriels au sujet d’ImageMagick (Utile pour le plugin doc2img)

http://valokuva.org/?cat=1

Les articles publiés sur le site

  • New builds for PHP 5.4 and PHP 5.3

    29 novembre 2012, par Mikko KoppanenImagick

    It’s been a while since I last updated this blog (September 2009 to be exact). Time flies! Anyway, here comes the actual content: updated imagick binaries for PHP 5.3 and PHP 5.4. The download package also includes ImageMagick 6.8.0 binaries compiled with VC9 (Visual Studio 2008). I noticed that the official ImageMagick builds are now Visual Studio 2010 and that wouldn’t work well with PHP compiled with 2008.

    I am not sure if I am violating any license in distributing ImageMagick binaries but if I do, please let me know and I will remove them. The binaries are just stock ImageMagick 6.8.0, which you can download from http://imagemagick.org/.

    In order to get things running you should add the ImageMagick DLL directory into PATH, add the imagick extension to php.ini and things should be running. At least hopefully.

    The download link for the binaries is here: imagick-php54-php53.tgz.

  • New builds for PHP 5.4 and PHP 5.3

    29 novembre 2012, par Mikko KoppanenImagick

    It’s been a while since I last updated this blog (September 2009 to be exact). Time flies! Anyway, here comes the actual content: updated imagick binaries for PHP 5.3 and PHP 5.4. The download package also includes ImageMagick 6.8.0 binaries compiled with VC9 (Visual Studio 2008). I noticed that the official ImageMagick builds are now Visual Studio 2010 and that wouldn’t work well with PHP compiled with 2008.

    I am not sure if I am violating any license in distributing ImageMagick binaries but if I do, please let me know and I will remove them. The binaries are just stock ImageMagick 6.8.0, which you can download from http://imagemagick.org/.

    In order to get things running you should add the ImageMagick DLL directory into PATH, add the imagick extension to php.ini and things should be running. At least hopefully.

    The download link for the binaries is here: imagick-php54-php53.tgz.

  • Perspective transformations

    9 juin 2010, par Mikko KoppanenImagick, PHP stuff

    Finally (after a long break) I managed to force myself to update the PHP documentation and this time it was distortImage code example. Things have been hectic lately but that does not quite explain the 6 months(?) break between this and the previous post. As a matter of a fact there is no excuse for such a long silence so I will try to update this blog a bit more often from now on.

    Back in the day I used to blog the examples and update the documentation if I remembered but I am trying to fix this bad habit. Most of the latest examples have been updated in to the manual. In the case of the two last examples I updated the documentation first and then blogged on the subject.

    I took some time to actually understand the perspective transformations properly using the excellent ImageMagick examples (mainly created by Anthony Thyssen) as a reference. The basic idea of perspective distortion seems simple: to distort the control points to new locations. Grabbing the syntax for Imagick was easy, an array of control point pairs in the form of:

    1. array(source_x, source_y, dest_x, dest_y ... )

    The following example uses the built-in checkerboard pattern to demonstrate perspective distortion:

    1. <?php
    2. /* Create new object */
    3. $im = new Imagick();
    4.  
    5. /* Create new checkerboard pattern */
    6. $im->newPseudoImage(100, 100, "pattern:checkerboard");
    7.  
    8. /* Set the image format to png */
    9. $im->setImageFormat('png');
    10.  
    11. /* Fill background area with transparent */
    12. $im->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
    13.  
    14. /* Activate matte */
    15. $im->setImageMatte(true);
    16.  
    17. /* Control points for the distortion */
    18. $controlPoints = array( 10, 10,
    19.                         10, 5,
    20.  
    21.                         10, $im->getImageHeight() - 20,
    22.                         10, $im->getImageHeight() - 5,
    23.  
    24.                         $im->getImageWidth() - 10, 10,
    25.                         $im->getImageWidth() - 10, 20,
    26.  
    27.                         $im->getImageWidth() - 10, $im->getImageHeight() - 10,
    28.                         $im->getImageWidth() - 10, $im->getImageHeight() - 30);
    29.  
    30. /* Perform the distortion */  
    31. $im->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
    32.  
    33. /* Ouput the image */  
    34. header("Content-Type: image/png");
    35. echo $im;
    36. ?>

    Here is the source image:
    checker before

    And the result:
    after

  • Fill patterns

    9 juin 2010, par Mikko KoppanenImagick, PHP stuff

    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:

  • phplondon conference 2008

    9 juin 2010, par Mikko KoppanenEverything else, Imagick, PHP stuff, phplondon08

    To summarize it: I had fun :) My conference preparations started about two weeks before the conference. The PHPLondon fellows (Paul, Matt and Richard) asked me to do a small presentation about Imagick at the pre-conference social event. The presentation I assembled ended up being a little over two hours, give or take. The hardest part was to trim down from two hours to about 40 minutes (I didn’t want to bore the people with too many code examples). The slides are available at http://valokuva.org/talks if you need them for some reason.

    My conference day was pretty hectic from the beginning to the end. I gave a few demos about the products that we represent and the moment I opened my mouth for the first time people started leaving the room. I hope that it had something to do with the “My Framework is better than yours?” talk starting at the same time ;)

    I met quite a lot of new people at the conference and of course it was nice to see the familiar faces from other conferences and PHPLondon meetings. I was especially happy that I was able to answer the questions Nigel James had ;)

    A huge thanks to the organizers for making this day possible!