Installing and Using ImageMagick with Imagick PHP Extension (php_imagick.dll) on WAMP

Posted: 2014-10-06 22:56:43

The php_imagick extension enables WAMP servers such as WampDeveloper Pro to create, edit, convert, and/or manipulate images via PHP using the ImageMagick software on Windows.

WampDeveloper Pro comes integrated with both the ImageMagick package and the Imagick PHP extension.

To enable the Imagick PHP Extension in WampDeveloper Pro:

1. Open file php.ini –
C:\WampDeveloper\Config\Php\php.ini

2. Near the end of php.ini, locate the ImageMagick section –

[ImageMagick]
;extension="C:\WampDeveloper\Components\Php\ext\php_imagick\php_imagick.dll"
;imagick.locale_fix=0
;imagick.progress_monitor=0

3. Uncomment the load line for this extension (remove the ‘;’ character from the beginning of the line) –

[ImageMagick]
extension="C:\WampDeveloper\Components\Php\ext\php_imagick\php_imagick.dll"

4. Save file. Restart Apache.

5. [optional] If not present already in your WAMP, download and extract PHP’s ImageMagick dependency files from http://windows.php.net/downloads/pecl/deps/, and into folder C:\WampDeveloper\Tools\ImageMagick\. Only extract the “\bin” files from the zip (and directly into the folder). This should match the environmental variable MAGICK_HOME=C:\WampDeveloper\Tools\ImageMagick set.

Afterwards, Imagick will be loaded by PHP and you can verify this via phpinfo.php…

imagick

5. Test imagick:

A. Create a scaled thumbnail image…

<?php

// if full path is not specified, will look for file in Apache's folder.

$im = new imagick('C:\WampDeveloper\Websites\www.example.com\webroot\imagick\pic.jpg');

// resize by 200 width and keep the ratio
$im->thumbnailImage(200, 0);

// if full path is not specified, file will end up in Apache's folder.

// write to disk
$im->writeImage('C:\WampDeveloper\Websites\www.example.com\webroot\imagick\pic_thumbnail.jpg');

echo 'Image Thumbnail Created.';

?>

B. Covert JGP image to PNG image format…

<?php

$image = 'C:\WampDeveloper\Websites\www.example.com\webroot\imagick\pic.jpg';

// a new imagick object
$im = new Imagick();

// ping the image
$im->pingImage($image);

// read the image into the object
$im->readImage($image);

// convert to png
$im->setImageFormat("png");

// write image to disk
$im->writeImage('C:\WampDeveloper\Websites\www.example.com\webroot\imagick\pic.png');

echo 'Image Converted.';

?>