Page 1 of 2

MagickWand For PHP Installation Instructions: Windows

Posted: 2005-08-15T16:04:52-07:00
by watson
.
UPDATED: Wednesday, September 14, 2005

Several changes have been made to this document -- if you have read it before, it may be in your best interest to skim it again.

The major changes are that there is now only one version of the DLL (per PHP version) that uses installed ImageMagick; the values of certain previously hard coded constants are now dynamically retrieved on module startup.

What this basically means is that the extension now retrieves all of its previously QuantumDepth-dependent values at module startup, not at compile time.

As a result, for those who want a direct shortcut, the list of available Windows DLLs is as follows:I STRONGLY advise that, unless you already know what QuantumDepth is, that you use the DLL listed as being compiled at QuantumDepth 8; it uses the least memory, and as a result is the fastest and best suited for web-based image processing.


MagickWand For PHP current version (as of 2005-09-13): 0.1.8

Based on / uses: ImageMagick 6.2.4-5 (minimum)

Download from: ftp://ftp.imagemagick.org/pub/ImageMagick/php/ (but read below first)

NOTE:
These instructions would benefit from a discussion of what ImageMagick's Quantum Depth means exactly, but I will leave that for another time / another venue.
Just know that a Quantum Depth of 8 (often noted as Q8 in ImageMagick's documents / filenames, as oppposed to Q16 and Q32) is preferred for use on the web.

Introduction

I have spent a large amount of time testing and hacking (think axe, not computer) to get this working (especially for Windows users), so I am going to use this page as a get-you-up-and-running document.

If you have any questions as to the INSTALLATION of MagickWandfor PHP on Windows, palce them in this topic, as I will receive notification of it in my email, and will be able to respond rapidly.

MagickWand For PHP Windows Release formats

In order to accomodate all the various options available to users of ImageMagick & PHP, i.e.:
(Quantum Depths 8, 16, 32) x (PHP 4, 5) x (ImageMagick static-lib-based, dll-based)

I have cobbled together a build / distribution system for MagickWand For PHP that tries to accomodate users varied requirements.

Some Advice

If you are a relative novice to the innards of ImageMagick / PHP / Web servers, or you just don't want to be bothered with the treatise which is to follow, my advice to you is to ask your Windows web server's administrator to download
(or do it yourself if you have the access) and place it in your webserver's PHP extension directory.

In the document, from this point on, I will refer to the MagickWand for PHP DLLs using the notation:
php-[PHP_V]_magickwand_q8_st.dll
where "[PHP_V]" serves as a stand-in for the PHP version of the DLL, either 4.4.0, or 5.0.4.

NOTE the php-[PHP_V]_magickwand_q8_st.dll) at the end of the name -- this indicates that the DLL is a static / self-contained / ImageMagick static lib-based DLL.

This PHP DLL is a fully working self-contained version of MagickWand For PHP (at ImageMagick Quantum Depth 8, more than adequate for the web), which uses no delegate programs, and will get you up and running very quickly.

All you have to do is make sure that the account under which PHP runs has read access to the file, and either put
extension="php-[PHP_V]_magickwand_q8_st.dll"

in your php.ini file, or, put
dl('php-[PHP_V]_magickwand_q8_st.dll');

before any statements that access the MagickWand For PHP API in your PHP scripts.

This ease comes at a price, however, as this DLL allows no access to any delegate programs, so you can't read the PDF / PS formats (although you can write them), along with being unable to read / write a whole slew of other formats which require delegate programs (MPEG, CGM, FIG, etc.).

The list of available formats follows:
BMP, BMP2, BMP3, CACHE, CAPTION, CLIP, CUR, DNG, EPDF, FAX, FRACTAL, G3, GIF, GIF87, GRADIENT, HISTOGRAM, ICO, ICON, INFO, JNG, JPEG, JPG, LABEL, MAP, MATTE, MIFF, MNG, MPC, MVG, NULL, P7, PATTERN, PBM, PDF, PFA, PFB, PGM, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PTIF, STEGANO, SVG, SVGZ, TEXT, TIF, TIFF, TILE, TTC, TTF, TXT, VID, XC

If an image format wasn't on that list, it can't be read / written by the MagickWand for PHP DLLs referenced above, as it was disabled in the source code.

Why? Size, speed and security.
  • Size: many of the formats ImageMagick manipulates it does so via API interfaces. With DLL-based ImageMagick, that is fine, as the code that is needed is located in external .dll files and is only loaded when needed. But for a self-contained / relocatable PHP DLL, all the ImageMagick+delegate code has to be compiled in, and that makes for a massive PHP DLL if all the possible formats were included.
  • Speed: more formats = larger PHP DLL = longer load time + more memory.
  • Security: some of the delegate formats are accessed via programs (Ghostscript, for example), and since part of the reason that I started down the MagickWand For PHP path was that I did not like more programs running on my server than were necessary, not to mention the possible security concerns (i.e.: exactly what is that program that is being run in the "background" doing?)
The static / self-contained DLLs are as common-web-image-format general purpose as possible.

If you need a particular format included in your lib-based DLL, send me a private message, and I will see what I can do.

Pre-Installation

For the intrepid, before installing MagickWand for PHP on a Windows system, you have to take stock of your situation, and ask yourself a few questions:
  1. Do you have control over the server where you are going to install MagickWand For PHP or can you get the administrator to install software and change server environment variables for you?
  2. Do the formats you will be handling require that ImageMagick use a "delegate" program to read or write them? (For example reading PDF / PS requires Ghostscript to be installed)
  3. Do you need access to formats not on the following list:
    BMP, BMP2, BMP3, CACHE, CAPTION, CLIP, CUR, DNG, EPDF, FAX, FRACTAL, G3, GIF, GIF87, GRADIENT, HISTOGRAM, ICO, ICON, INFO, JNG, JPEG, JPG, LABEL, MAP, MATTE, MIFF, MNG, MPC, MVG, NULL, P7, PATTERN, PBM, PDF, PFA, PFB, PGM, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PTIF, STEGANO, SVG, SVGZ, TEXT, TIF, TIFF, TILE, TTC, TTF, TXT, VID, XC
    (Please note: NONE of the X-11 based formats are listed as installed by default!)
There are probably more questions you need to ask, but these are the most important for the task at hand.

If #2 and #3 are true, you need #1 to be true, or you may need to contact me for a custom solution.

Installation

If you do have control of the server or can get things done on the server, and can install the ImageMagick DLL-based setup distribution, you have the opportunity to have access to the full ImageMagick feature set (read: "access to all the formats ImageMagick is capable of manipulating, as long as you have the required delegate libraries / programs installed").

This does not mean however, that you are required to do this; again, I recommend just installing the self-contained version.

If you do have server control, or can get your friendly neighborhood server admin to do some alterations for you, here's what you need to do / have done...
  1. First, install the DLL-based ImageMagick version (or higher) referenced at the start of this document. For Windows, the setups can be found here:

    The files you need are named
    ImageMagick-[VERSION]-Q[QUANTUMDEPTH]-windows-dll.exe

    e.g.: ImageMagick-6.2.4-0-Q8-windows-dll.exe

    I suggest the Q8 version, as it is faster / less memory intensive than the other options, and is perfect for the web.

    It would be wise to install ImageMagick to a directory whose path contains no spaces, so the default
    "C:\Program Files"
    is not a good location.

    Also, think ahead -- DO NOT install ImageMagick to a version numbered directory, e.g.:
    C:\ImageMagick-6.2.4

    Instead, install it into a generic directory, e.g.:
    C:\ImageMagick
    so that when you upgrade it, you won't cause yourself confusion, and you won't have to change your setup (see next section).
  2. Next, add the ImageMagick_Install_Dir (wherever you installed ImageMagick) to your server's
    PATH

    environment variable, and add
    MAGICK_HOME=ImageMagick_Install_Dir

    to your web server's environment variables. An example of how do this in Apache is
    SetEnv MAGICK_HOME C:/ImageMagick/Q8-DLL

    The PATH variable is used to find ImageMagick's DLLs so they can be loaded into memory, and the MAGICK_HOME variable is used by ImageMagick to find it's delegates.
  3. Download the appropriate DLL
    to your PHP extension directory.

    Note the _dyn (for dynamic), as this PHP DLL searches at runtime (i.e. dynamically) for the ImageMagick libraries on which it depends.
  4. Put
    extension="php-[PHP_V]_magickwand_dyn.dll"

    in your php.ini file, or, put
    dl('php-[PHP_V]_magickwand_dyn.dll');

    before any statements that access the MagickWand For PHP API in your PHP scripts.
Additional Information

Read:
for additional information.

Contact Developer

Click here to send me a private message through the message board.

Posted: 2005-08-18T12:17:41-07:00
by watson
sf-andrew:

I am the first to express my complete ignorance of all things IIS.
  • Is PHP running as a CGI or module?
  • Is the DLL the correct version for your version of PHP (post what that version is, please)?
  • Let's see... are the permissions on the DLL set so that it allows the user the server is running under to access it? (This is a bit of a stretch on Windows, but its worth a try...).
  • Try downloading the static version of the DLL for your version of PHP, and see if it loads...
Post what happens.

Posted: 2005-08-18T14:10:13-07:00
by watson
ASAPI -- good. (Good for me to find some things out, maybe not so good for you right now -- sorry).

With the IIS ASAPI stuff, the environment variables may not be so easily accesible to PHP (see the second post on http://us2.php.net/getenv). I am just guessing here though.

The other PHP extensions probably don't have to load any external DLLs (except for the native Windows DLLs, that is) as the MagickWand for PHP extension (the dynamic version) does, so that may be why you don't have any issues with them.

Yes, you probably should restart the IIS server in order to use the new (static) DLL as ASAPI PHP is always in memory, and would probably have to be reloaded to access the new DLL.

Post your results.

Posted: 2005-08-18T17:54:38-07:00
by watson
sf-andrew:

Ok... a lot to cover here...

First: "static dynamically linked library". I assure you, the extreme contradiction in terms was not lost on me, when I realized that that was what was necessary to enable programmers on Windows to use MagickWand for PHP. It is actually kinda funny, in a programmer in-joke way.

You say that phpinfo() was reporting that the DYNAMIC DLL was recognized? If so, then what was that error you mentioned about? When did that occur?

As for MediaWiki, this page:
seems to indicate that MediaWiki uses the "php_imagick.dll" extension (Imagick), available here:
with a precompiled version available in this package here:

Follow the Instructions on the MediaWiki FAQ page and you should be ok.

As for why MagickWand for PHP is not what you want right now, MagickWand for PHP is not yet as widely known as Imagick, (purposely done, until I had time to work out kinks like this), so most open PHP programmers/projects don't yet know about its GLORIOUS capabilities :wink:

However, at the base of everything you were talking about, is a slight misunderstanding of exactly what MagickWand for PHP is.

MagickWand for PHP is an API -- a programming interface to the functions of the ImageMagick image manipulation system.

It does not enable you to run "convert" or any of the other programs in the ImageMagick distribution -- they come with ImageMagick, but MagickWand for PHP does not call them AT ALL.

Instead, MagicWand for PHP DIRECTLY accesses the same system that they use to do image processing, without the additional overhead of running a separate program.

Imagick, then, is very similar to MagickWand for PHP, except in the following ways:
  1. Imagick is older than PHP
  2. As as result, Imagick is rather better known that MagickWand for PHP
  3. However, Imagick is known to run on ImageMagick v5, with somewhat limited support for v6,
  4. Whereas MagickWand for PHP is based on ImageMagick's MagickWand interface which only exists in ImageMagick v6.
  5. MagickWand for PHP enables access to ALL the functionality that the ImageMagick programs have access to
  6. At the time of MagickWand for PHP's creation, Imagick's access to much of ImageMagick's functionality was rather limited
  7. Those limitations, in addition to Imagick's propensity to crash PHP when you made a mistake in the code (and sometimes when you did everthing perfectly), combined with it's lack of obedience to PHP's safe_mode and openbasedir restrictions, spurred me on to develop MagickWand for PHP.
  8. MagickWand for PHP is an almost direct mapping of ImageMagick's MagickWand C API to PHP -- it uses the same function names as the ImageMagick C API
  9. Imagick creates its own function names, so MagickWand for PHP IS NOT a drop-in replacement for Imagick -- you have to use one or the other.
I hope this helps.

Posted: 2005-08-18T17:59:57-07:00
by watson
Collyn:

Make sure you restart the computer that Apache 2 is on.

Apache does not seem to recognize the updated PATH unless the computer is restarted.

Posted: 2005-09-14T04:54:06-07:00
by watson
I have reduced the number of files Windows users have to worry about, and simplified the directory structure of the ftp site (see the top of this topic).

I thought that I would have a bit of time before the next mirror to update this document (as the ImageMagick main ftp site is supposed to be mirrored once a day), but I guess I was wrong.

Nevertheless, the above instructions have been updated.

Posted: 2005-11-05T04:20:23-07:00
by watson
I do not have much time to currently spend on MagickWand at the moment, but I will try to lend as much assistance as possible.

However, you have to be specific, the more specific, the better.

So, for example, when you state:
hezedgodson wrote: Whatever dll I give in the php.ini file, its showing the error "PHP Startup: Unable to load dynamic library 'c:/php/ext/php-4.4.0_magicwand_dyn.dll' - The specified module could not be found.".
I am left a bit confused.

First, you say you are using PHP 5.0.0; therefore you should not be using ANY of the PHP4 DLLs. Furthermore, if you are receiving that EXACT message each time, that means that the reference to the "php-4.4.0_magicwand_dyn.dll" file has not been commented out properly.

Secondly, unless you have an already installed and properly set up version of the ImageMagick Windows distribution that the *_dyn.dll DLLs can access, that particular error message will show up, as the DLL will be trying to access ImageMagick DLLs that do not exist.

Thirdly, the PHP 5.0.0 version you are using is an out of date version of PHP (the current PHP 5 version is 5.0.5). I do not know if this would cause that type of error, but it might.

So, do some more testing, (maybe re-read http://redux.imagemagick.org/discussion ... php?t=4708) and get back to me.

I hope I was of some help.

Posted: 2006-02-08T11:11:26-07:00
by magick
The MagickWand for PHP library is being maintained. In fact a new version is scheduled for release in the near future that addresses some of the problems posted here. The delay in getting back to postings in this group is simply that there is too much work to do and too few volunteers. If you want to volunteer, we have a tons of work that must get done that could help free up time for the primary developers to answer questions on this forum. Currently, you will get an answer but it may take a month (or more) given our work load. In the mean-time lets hope a knowledgable user can post answers to pending questions in the forum.

Posted: 2006-11-08T03:39:34-07:00
by snowbydave1
Please anybody guide me.

I have PHP 5.4.1 with Win XP.

I am receiveding following error

PHP Startup: Unable to load dynamic library 'C:/php/ext/php-5.0.4_magickwant_q8_st.dll' - The specified procedure cound not be found.

Though I had given following thins correctly in php.ini file.

extension=php-5.0.4_magickwand_q8_st.dll


Thanking you,


SnowbyDave

Posted: 2007-01-22T16:52:36-07:00
by DianaSg
Anyone got it working in 5.1.4 Windows Xp?
Followed the instructions, but the dll is not loaded as seen in phpinfo nor I am given an error message from php.
Have done the following:
1. Installed 6.3.2 ImageMagick qt8 DLL
2. Run to CMD and add PATH to ImageMagickDir and check that env var MAGICK_HOME is set to ImageMagickDir
3. Download the appropriate DLL 5.2.0 DLL and copy to Ext Dir
4. Added extension=filenameofdll to php.ini
5. Restart Apache

Re: MagickWand For PHP Installation Instructions: Windows

Posted: 2007-06-25T11:05:59-07:00
by Jip
watson had posted back in 2005:

"If you need a particular format included in your lib-based DLL, send me a private message, and I will see what I can do."

He is no longer a registered user where I can contact him. I need to convert ai files into jpg, eps, gif, and png. Any recommendations?

Re: MagickWand For PHP Installation Instructions: Windows

Posted: 2007-06-25T11:53:46-07:00
by magick
Watson is no longer available-- he just disappeared. However, the ImageMagick developers have taken over the project so MagickWand for PHP is well supported.

Re: MagickWand For PHP Installation Instructions: Windows

Posted: 2007-06-25T12:19:37-07:00
by Jip
magick wrote:Watson is no longer available-- he just disappeared. However, the ImageMagick developers have taken over the project so MagickWand for PHP is well supported.
Thanks for the info. Is there someone to contact regarding adding the ai format to the list of supported MagickWand for php file formats?

Re: MagickWand For PHP Installation Instructions: Windows

Posted: 2007-06-25T12:41:29-07:00
by magick
Post a URL to a couple of AI image files that we can download and test. We'll get back to you on how difficult it would be to support the format.

Re: MagickWand For PHP Installation Instructions: Windows

Posted: 2007-06-25T14:13:00-07:00
by Jip
magick wrote:Post a URL to a couple of AI image files that we can download and test. We'll get back to you on how difficult it would be to support the format.
Here the locations of the files:

http://www.externalssp.com/graphic1.ai
http://www.externalssp.com/graphic2.ai

Thanks for looking into this.