Using ImageMagick with PHP

There is a PHP mod­ule for Imagemag­ick, called imag­ick, sort of like the one for GD.

Fol­low­ing is some sim­ple code that has worked for me:

if(!extension_loaded('imagick')) { dl('imagick.so'); }
$handle = imagick_create();
imagick_set_attribute($handle,array("quality"=>1,"magick"=>"png"));
imagick_set_attribute($handle,"size","98x20");
imagick_read($handle,"xc:#cccccc");
imagick_annotate($handle,array(
"primitive"     =>  "text 10,14 hello",
"pointsize"     =>  16,
"antialias"     =>  1,
"stroke"        =>  "#000000",
"font"          =>  "arial.ttf"
));
$handle = imagick_copy_rotate ($handle, 270);
header("Content-type: image/png");
imagick_dump($handle,"png");
8 comments
  1. superD says: Aug 28, 200411:49 am

    would it be pos­si­ble that you may make it a bit more spe­cific for the non-programmers??
    such as "save as" and the next next step…etc??
    if it's pos­si­ble would be great, love to use it on my site. Thanks!

  2. Vince says: Oct 03, 20042:00 am

    There are more in-depth exam­ples about how to use the IMAGICK PHP exten­sion here:

    http://pecl.php.net/get/imagick-0.9.11.tgz
    http://pecl.php.net/package/imagick

    The Samples/ direc­tory con­tains about 30 exam­ples on how you can use IMAGICK

    –Vince
    Biosonik.com

  3. Ben says: Jan 31, 20057:51 pm

    I think you are right. One neat thing, I\'d have never pre­dicted with the inter­net, is that the sites are stay­ing around, so that peo­ple can find them, read them and learn from them. The worst thing about the .edu inter­net was data rot (a form of link rot) where resources and knowl­edge went into the vapor every semester.

  4. blub says: Feb 01, 200611:00 am

    But what good are web­sites and ref­er­ences, if the soft­ware in ques­tion is not being actively devel­oped. The imag­ick modul for exam­ple has so many bugs and glitches, and it seems that no one is tak­ing care of it. So I wish some­one would update all those web­sites, instead of them still being there, point­ing to the same old (out­dated) information.

  5. […] Re: Imagemag­ick / apache / php Accord­ing to this, the PHP inter­face is called imag­ick, not Imagemag­ick. Though the lat­ter is prob­a­bly also required. Zyp­per show no such pack­age called imag­ick in the repos so you may have to build your own from PEAR. Or maybe there is an Open­SUSE repo with it pre-built. Using ImageMag­ick with*PHP | Sniptools | […]

  6. Webagentur says: Mar 30, 200910:54 pm

    Thank you, this lit­tle tut has me very helped.

  7. links for 2010-01-20 « ueXpected says: Jan 21, 20104:02 pm

    […] Using ImageMag­ick with PHP | Snip­tools | Mis­cel­la­neous (tags: php imageslicing) […]

  8. mayank says: Aug 18, 20108:38 pm

    how to install it on a webhost..do i have to ask them to install it for me

Submit comment