Using ImageMagick for WordPress Thumbnail Generation

When you upload an image in WordPress, the blogging software tries to generate several scaled versions of the images uploaded. So after it’s done, WordPress provides 4 different sizes of the image for you to insert into the post – thumbnail, small, large, original.

I noticed that for my WordPress install, only the original image was available and the other options were disabled. The reason is that the PHP on my server was compiled by me myself and I didn’t compile many of the extensions. WordPress uses GD extension for thumbnail generation. But this time I didn’t recompile PHP with GD (I didn’t know how to compile GD alone as an extension). Instead I used ImageMagick and here’s the whole process.

My server setup

My server OS is CentOS 5.4 (x86_64). PHP wasn’t installed via yum but compiled with configure command:


'./configure' '--prefix=/usr/local/php' '--with-mysql' '--with-mysqli' '--enable-mbstring=all' '--with-libdir=lib64' '--enable-suhosin' '--with-zlib' '--with-mcrypt' '--with-curl'

Install ImageMagick

I used yum to install it.


yum install ImageMagick.x86_64
yum install ImageMagick-devel.x86_64

Compile imagick extension

Download the imagick extension source here.


cd imagick-x.x.x
/usr/local/php/bin/phpize
./configure --with-imagick=/usr/local --with-php-config=/usr/local/php/bin/php-config
make
make install

Since my PHP wasn’t installed in the “standard” location (and the bin dir was not in PATH) I had to use full path to `phpize`, and specify the `php-config` location in configure command. The make program uses php-config to decide where to put the compiled extension (php-config –extension-dir).

Add this line to php.ini:


extension=imagick.so

and restart web server. After that I checked phpinfo() output and saw imagick extension’s information there.

Let WordPress use imagick extension to generate thumbnails

Install ImageMagick Engine plugin. Note that you have to configure it after activation or it won’t work. With this plugin, you can even configure it to generate selected sizes only. I only wanted the thumbnail.

According to the plugin’s description, ImageMagick improves image quality dramatically over GD.

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your intelligence before hitting * Time limit is exhausted. Please reload CAPTCHA.