Install ImageMagick with PHP on Debian

来源:互联网 时间:1970-01-01

I’ve been working on an app lately that involves some image manipulation. Most of the time I use GDfor image manipulation but there are a lot of things it just can’t do easily.

When I run into prolems GD can’t solve, I turn to ImageMagick.

ImageMagick is great, it’s powerful and easy-to-use. Unfortunately, it’s an enormouse pain to install and set-up.

It was far from easy setting it up on Debian / Ubuntu — so here’s how I did it. I hope it helps.

1. Install ImageMagick

You can get ImageMagick and its dependencies from the apt-get repository.

sudo apt-get updatesudo apt-get build-dep imagemagick 2. Get The PHP Dev Package

In order to use PHP to interact with ImageMagick you’ll need this package.

sudo apt-get install php5-dev 3. Get the PECL Imagick Package

Now that you have the PHP Dev tools and ImageMagick, you just need the Imagick package to interface between PHP and ImageMagick.

pecl install imagick 4. Write Some Sweet PHP / ImageMagick Code

Now you can use a ton of great tools, check out a listhere!

<?php $thumb = new Imagick(); $thumb->readImage('myimage.gif'); $thumb->resizeImage(320,240,Imagick::FILTER_LANCZOS,1); $thumb->writeImage('mythumb.gif'); $thumb->clear(); $thumb->destroy(); ?>