Installing ImageMagick on Windows -- Setup Imagick on PHP

I had a tough time yesterday trying to install ImageMagick on Windows. I got the correct binary file, but when I tried to invoke it with the PHP extension (php_imagick.dll) it was not getting loaded at all!!. Searching all over the web did not help..Finally I managed to fix the problem and felt I should give a clear procedure that will help anybody to install ImageMagick on Windows XP with proper DLL file for PHP. Here is what I did and if you do the same, you should get this working without any problems..

ImageMagick References

Step 1 : Do not download the latest version of ImageMagick. Rather download this version : ImageMagick-6.4.1-0-Q8-windows-dll. You can get this version from the following link . You get all the versions here. Make sure you pick the right one. If you miss here, you are gone!

Step 2: After downloading it, install the binary. Do not install it to c:\program files..etc..rather install it to a location like c:\imagemagick. (assuming c: as your root directory).

Step 3: After installation, run the 'convert' command from DOS mode. It should work. If it does not, check the PATH environment variable and make sure that 'c:\imagemagick' is added correctly there.

Step 4: We need to add one more environment variable MAGICK_HOME. (New one). The value of this variable should hold the directory path where imagemagick is installed. (c:\imagemagick in this case)

Step 5: I need to set this up on Apache 2.2x with PHP 5.2.6. In the Apache httpd.conf file, add this line to the end of the file. "SetEnv MAGICK_HOME “C:/imagemagick” (without quotes and watch the '/'..Make sure that you refer to the correct path here).

Step 6: Download the correct extension file for PHP. If you are using the same version that I have listed, then you can get the extension from here. If this link is broken, let me know.

Step 7: PHP.ini file needs to be updated. Identify the extension directory for PHP correctly and place the DLL file inside the directory. Update the PHP.ini file with this extension.

Step 8: Restart Apache once all this is done.

Step 9: After restart, make sure that the imagick extension got loaded correctly with phpinfo(). If you have done all the above steps correctly, and the extension dll has not got loaded, then you have picked up an invalid dll file. Check the file.

Step 10: Execute a sample code like this (add php header tag)


thumbnailImage(100, 0);
echo $image;
?>

It should work and you are done!!

If you get an error like this

PHP Fatal error: Class 'Imagick' not found in....

Then, the extension file is not loaded properly. Check the extension file.

Any queries, comment in the blog. I shall help to resolve it.. Also, check out the following books..They are highly useful








34 comments:

  1. Hello, thank you for your tutorial.
    But although i did exactly what you have written the php_imagick dll is not be loaded. It drives me cracy. Please help!!!

    ReplyDelete
  2. Hi,

    Did you picked the right version? Can you post the version including your operating system details?

    Also, the output of your php_info()...

    ReplyDelete
  3. Same here.

    When you are using WampServer software you'll have to add the extension to both the php.ini and the php.ini in the windows directory.

    Source: http://nl3.php.net/manual/en/install.pecl.windows.php

    I now have the extension placed in both php.ini's, wampmanager.ini(so it shows up in the menu) and httpd.conf.

    The httpd.conf environment variable is displayed in phpinfo() ,the imagick extension, however is not.

    When I restart the Wampserver software it raises the following error: CORE_RL_wand_.dll cannot be found.

    Is this part of the imagick library?

    ReplyDelete
  4. Installation ok.

    Now, any idea on how to add jpg/png support for saving jpg/png images? I read that onli gif is supported natively, while those "delegates" must be installed manually, so they let you download zips (http://www.imagemagick.org/download/delegates/) of .c files to be compiled? I wonder: are you kidding me?

    Any help?

    ReplyDelete
  5. Hello and thanks for taking the time to post this.

    I need to set this up in Apache 2.2 and PHP 5.26 as well. I carefully followed all the instructions, but when I restart Apache, it keeps showing the following warning message and won't load the library:

    PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\xampp\\php\\ext\\php_imagick_dyn-Q8.dll' - The specified module could not be found.\r\n in Unknown on line 0


    The path it is reporting is exactly where the DLL file is. Any ideas?

    BTW, I used this binary:

    http://image_magick.veidrodis.com/image_magick/binaries/ImageMagick-6.4.1-0-Q8-windows-dll.exe

    And the same extension file you used.

    ReplyDelete
  6. Hmm... a Windows restart did the job. THANK YOU VERY MUCH!

    ReplyDelete
  7. After days of pain and suffering trying to get Imagick to load on my windows server I found your post. Following your instructions, I was finally able to get it to work. Thanks for the posting.
    Joel

    ReplyDelete
  8. After many failed tries, finally I'got this blog and I could put ImageMagick to work on my system,I'm using IIS instead of Apache in Windows XP. Thank you very much!

    ReplyDelete
  9. Great tutorial... Finaly something that works. I'm using WAMP server and this is first place after hours of searchng with all the right steps how to install. Thanks!

    ReplyDelete
  10. Thanks a lot for your tutorial. I had to change but one bit for my WAMP installation:
    I used the php_imagick_st-Q8.dll from mikkos's blog.
    Then it worked - otherwise I only got
    PHP Fatal error: Class 'Imagick' not found

    ReplyDelete
  11. Thanks for posting this - it is brilliant. I've been trying to install imagick on windows for days and have finally succeeded with the help of this.

    I am using Xampp v1.7 on XP. Used the ImageMagick version suggested above downloaded from here: http://image_magick.veidrodis.com/image_magick/binaries/

    together with the .dll posted in step 6.

    ReplyDelete
  12. Hey, The link to the extension file in Step 6 is broken. Do you have an alternate location for this dll?

    ReplyDelete
  13. On a 2003 windows server 32bit I had to install visual c++ runtime libraries 2005 and 2008 to get it running.

    ReplyDelete
  14. Thanks anonymous for the: "On a 2003 windows server 32bit I had to install visual c++ runtime libraries 2005 and 2008 to get it running."

    That solved my issue as well.

    ReplyDelete
  15. Great Tutorial.
    You have saved my life.
    It works fine with my 4images gallery

    ReplyDelete
  16. I tried this and I get the error: 500 - Internal server error.
    There is a problem with the resource you are looking for, and it cannot be displayed. Do you know why this is?

    ReplyDelete
  17. @Ken

    Have you setup your PHP correctly? Can you post some information on your configuration files in webserver?

    ReplyDelete
  18. Hi - I am certainly glad to find this. great job!

    ReplyDelete
  19. hi, Your tutorial is greate job....But Not useful me

    ReplyDelete
  20. @Ajay, can you post your exact problem?

    ReplyDelete
  21. Hi, thanks for the tutorial and it has got me the furthest so far BUT! When I try and run a simple test script, my browser displays a connection reset page.

    In my phpinfo, all expected info is there.

    Any ideas? Thanks for your help..

    ReplyDelete
  22. Hi,

    I only got some parts running:

    WAMP-Environment:
    Windows: 7 Pro, 64 bit
    Apache: 2.2.17 (Win32)
    PHP: 5.3.10 MSVC9 (Visual C++ 2008) x86
    Imagick: 6.7.6 Q16 x86

    Imagick shows up in phpinfo() correctly and works for creating new images from scratch.

    As soon as a function like readImage is called, I get an "500 Internal Server Error", Logfile message: "[Mon Mar 12 20:45:40 2012] [error] [client 127.0.0.1] Premature end of script headers: php-cgi.exe, referer: http://localhost/test/"

    All Programms (Apache, PHP, Imagick are NOT installed in Windows default programm directory, all path do not contain spaces).

    Anyone has an idea?

    ReplyDelete
  23. Step 3: After installation, run the 'convert' command from DOS mode.

    ...what?

    ReplyDelete
  24. hello admin,

    i am using a windows server 2008 64 bit and i have spent almost 20 days but no luck. it is installed but i can't see this is my its library in phpinfo

    please help me

    ReplyDelete
  25. great post,all links for the .dll file are broken though, do you have a recent link?

    ReplyDelete
  26. Hey, Thanks for the tutorial. But the link you mentioned "http://www.valokuva.org/" is broken. Do you have any other link where I can get download the vc9 compiled imagick dll.

    Thanks

    ReplyDelete
  27. i am using wampserver-2.2 windows 32 bit which imagemagick version suitable for that & its corresponding dll file?
    i am not getting rid out of imagemagic .dll file not found error .please send me sorrect downloading link

    ReplyDelete
  28. wampserver 2.2 windows 32-bit which imagemagick version suitable for php 5.3.13 & its corresponding dll file?please send me correct link for that .each time i am getting imagemagick.dll not found error

    ReplyDelete
  29. link to dll is broken

    ReplyDelete
  30. hello,
    i have installed imagick on server in c://Imagick

    i also make some changes in my php.ini file : extension=php_imagick.dll
    but still i got the error of fatal error that say the class imagick is missing.
    what is the resolution

    ReplyDelete