Getting ImageMagick to run on XAMPP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Getting ImageMagick to run on XAMPP

Postby TomXampp » 01. December 2015 20:51

My webserver has ImageMagick installed and available (and works correctly), and so I want to make use of it. To do that, I need to run it on my localhost to test code, etc.

I'm using the current version of XAMPP (Version 5.6.14) with Apache/2.4.17 (Win32) and PHP/5.6.16 on Windows 8.1

To install ImageMagick locally, I created this directory off the root:

c:\ImageMagick

Then, from here:

http://windows.php.net/downloads/pecl/deps/

...I downloaded the X86 thread-safe version that would match the DLL (which you have to obtain separately, which mystifies me). The version I downloaded was:

ImageMagick-6.9.1-2-vc11-x86.zip

I unzipped it to C:\ImageMagick and then *moved* the contents of its "bin" subfolder to C:\ImageMagick, so that everything is in the root of that directory.

I then added C:\ImageMagick to my PATH and verified that it worked by first exectuting "convert" from a command line at a different directory, which then caused the help screen info to display. I then further verified it worked by performing an image resizing from the command line successfully. So far so good.

Then, following the advice culled from other online postings about how to do this, I copied the CORE_RL_*.DLL files and the IM_MOD_RL*.DLL files from C:\ImageMagick to c:\xampp\apache\bin

I then added this system environment variable:

Code: Select all
MAGICK_HOME=c:\imagemagick


The next step is to add php_imagemagick.dll to the php\ext folder in XAMPP, but there's no such DLL among those in the ImageMagick ZIP files/EXEs. To get it, I had to go here:

http://windows.php.net/downloads/pecl/releases/imagick/3.3.0rc2/

...and download:

php_imagick-3.3.0rc2-5.6-ts-vc11-x86.zip

...I then unzipped it to a dedicated "junk" directory and copied the php_imagemagick.dll file it contained to c:\xampp\php\ext

I then edited the php.ini file in c:\xampp\php to include this directive:

Code: Select all
extension=php_imagemagick.dll


Now...the moment of truth:

I started XAMPP and checked the PHP_ERROR_LOG, and found no errors. I then ran PhpInfo.php and confirmed that ImageMagick was loaded; here is the screen shot:

Image

Now, when the following script is run from my live server (DreamHost), it successfully converts the X.JPG image as indicated:


Code: Select all
<?php
if (!extension_loaded('imagick')) {
    echo "imagick not installed...";
} else {
   echo "imagick installed...";
}
echo "Start...";
$uploaded_filename = "x.jpg";
$im = new Imagick();
echo "Created object...";
$im->readImage("x.jpg");
echo "Read JPG...";
$im->resizeImage(528, 0, Imagick::FILTER_LANCZOS2SHARP, 1);
$im->stripImage();
$im->writeImage("x_lg.jpg");
$im->clear();
$im->destroy();
echo "Done."
?>


However, when I run it from my XAMPP localhost, it gets as far as creating the $im (ImageMagick object), but it does not proceed to read in the image with the readImage() function ("Created object..." is written to the screen, but nothing beyond that, and no output file is created).

Any suggestion as to what I may have omitted in my installation?
TomXampp
 
Posts: 59
Joined: 12. March 2015 03:58
Operating System: Windows 8.1

Re: Getting ImageMagick to run on XAMPP

Postby TomXampp » 03. December 2015 09:23

I've found the answer to my own question, and perhaps it will help others. It turns out that ImageMagick needs the full path to your image files, even if they are in the same directory as the script that is executing ImageMagick on them. It's that simple. Here's how to do it:

Say your images are kept in an "images" folder off the root of your site. On XAMPP localhost, the full path might be:

C:/xampp/htdocs/mysite/images/x.jpg


Thus:

Code: Select all
 $_SERVER['DOCUMENT_ROOT'] would hold "C:/xampp/htdocs/mysite";
    $path_to_your_files = "images/";
    $image_file_name = "x.jpg";


Put it all together with this string:

Code: Select all
 $my_image = $_SERVER['DOCUMENT_ROOT'] . "/" . $path_to_your_files . $image_file_name;


On the live server, the full path might be:

/the_inaccessible_superfolders_of_your_website/mysite.com/images/x.jpg


Thus:

Code: Select all
 $_SERVER['DOCUMENT_ROOT'] would hold "/the_inaccessible_superfolders_of_your_website/mysite.com"
    $path_to_your_files = "images/";
    $image_file_name = "x.jpg";


Again, put it all together with this string:

Code: Select all
$my_image = $_SERVER['DOCUMENT_ROOT'] . "/" . $path_to_your_files . $image_file_name;


That is what must be fed into
Code: Select all
new Imagick($my_image);
in order for it to work. I hope this helps someone else struggling with this issue.
TomXampp
 
Posts: 59
Joined: 12. March 2015 03:58
Operating System: Windows 8.1


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 57 guests