Building php_imagick.dll from imagick-2.2.2.tgz

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Mitron

Building php_imagick.dll from imagick-2.2.2.tgz

Post by Mitron »

I recently downloaded the latest imagemagick src and built it on Windows using VS 6.0 which creates a number of CORE*.dll files. The config.w32 for imagick-2.2.2.tgz is looking for two of these files that don't seem to exist in the latest imagemagick src, i.e.

CORE_RL_coders_.lib
CORE_RL_filters_.lib

These seem to have changed over to multiple files, i.e.

IM_MOD_RL_*.lib
UTL_*.lib

I was able to remove the two calls in the config.w32 file and everything seems to have compiled and so far works for the few tests I've done so far. Just curious if this will be fixed soon or will we continue to have to edit config.w32 in order to have PHP add the extension?
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by mkoppanen »

First of all, amazing that you managed to compile on Windows!

A few questions:

a) Can you provide the changes as a patch you did to the standard config.w32?

b) Are you sharing the binaries somewhere? I could link to your builds from here http://valokuva.org/?page_id=50 if you have them somewhere online or even host the binaries for you.

c) Are you doing thread-safe and non-thread-safe builds?
Mikko Koppanen
My blog: http://valokuva.org
Mitron

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by Mitron »

mkoppanen wrote:First of all, amazing that you managed to compile on Windows!
Oh, I didn't realize this was something new. I saw the config.w32 file so I just assumed it would work.
mkoppanen wrote:a) Can you provide the changes as a patch you did to the standard config.w32?
Sure, I just removed those two lines (9 and 10), i.e.

Code: Select all

			&& CHECK_LIB("CORE_RL_coders_.lib", "imagick", PHP_PHP_BUILD + "\\lib\\imagemagick;" + PHP_IMAGICK)
			&& CHECK_LIB("CORE_RL_filters_.lib", "imagick", PHP_PHP_BUILD + "\\lib\\imagemagick;" + PHP_IMAGICK)
EDIT: While this does build with PHP, the resulting php_imagick.dll doesn't show any supported extentions in phpinfo() so it shouldn't work at all. I believe I substituted the two missing files from the zip.zip file for PHP builds to make it work.
mkoppanen wrote: b) Are you sharing the binaries somewhere? I could link to your builds from here http://valokuva.org/?page_id=50 if you have them somewhere online or even host the binaries for you.
Not really, I just got them built yesterday with vc6. It seems to work on XP but I have an issue on Windows 2003. I'm attempting to track that down now.
mkoppanen wrote: c) Are you doing thread-safe and non-thread-safe builds?
I beleive thread-safe at the moment, but I should be able to do both.

Building it was difficult but mainly because of all the prep work you have to do for PHP before you can even start and because I'm a bit green with VC6. I had to update the php_build folder with the libs and includes for magic, Magic++ and wand, placed the imagick-2.2.2 folder in the PHP src ext folder and renamed it to imagick, then I built PHP --with-imagick=shared to create the php_imagick.dll.

This works on WIndows XP Professional, but not my WIndows 2003 Server. This may just be an enviornment variable or something, but I'm looking into it. I was hoping you would know whether or not we need the new libs added to replace the other two files since they don't exist in the binary or src builds of imagemagick any more. :)
Last edited by Mitron on 2009-03-02T04:28:04-07:00, edited 1 time in total.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by mkoppanen »

Do the two files exist if you compile a static version of ImageMagick?
Mikko Koppanen
My blog: http://valokuva.org
Mitron

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by Mitron »

Yes, as a matter of fact it does create those files using a static build. However, there are issues with the static builds. After spending a whole day or two testing all this out I found that VS6.0 will build the Dynamic, Single Thread, Multi Thread and Multi Thread DLL but for whatever reason I can't get it to build Multi Thread (without DLL) of ImageMagick(Be sure to update your SDK).

After building the four types of ImageMagick that would build, I attempted to build imagick-2.2.2 against the four ImageMagick builds. See results below:
Last edited by Mitron on 2009-03-02T05:02:58-07:00, edited 2 times in total.
Mitron

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by Mitron »

ImageMagick Dynamic Build 6.4.9-7 (X11 checked)
  • imagick-2.2.2 won't build due to missing libs (CORE_RL_coders_.lib,CORE_RL_filters_.lib)
  • if I copy these files from the static builds and add to the dynamic ones, imagick will build and seems to work on XP
  • Will not work on Windows 2003 (Apache won't load php_imagick.dll or errors trying to load PNG files)
ImageMagick Single Thread Build, Multi Thread (without dll)
  • imagick won't build, I get the following errors:

Code: Select all

imagick.c
..\php_build\include\imagemagick\magick/magick-config.h(164) : warning C4005: 'i
nline' : macro redefinition
        Zend\zend_config.w32.h(65) : see previous definition of 'inline'
MagickWand lib static interface
MagickWand module static interface
Magick lib static interface
Magick module static interface
imagick_class.c
ext\imagick\imagick_class.c(8264) : warning C4700: local variable 'intern' used
without having been initialized
imagick_helpers.c
ext\imagick\imagick_helpers.c(462) : warning C4101: 'final_filename' : unreferen
ced local variable
imagickdraw_class.c
imagickpixel_class.c
ext\imagick\imagickpixel_class.c(377) : warning C4761: integral size mismatch in
 argument; conversion supplied
imagickpixeliterator_class.c
        rc /fo Release_TS\php_imagick.dll.res /d FILE_DESCRIPTION="\"Imagick\""
/d FILE_NAME="\"php_imagick.dll\"" /d PRODUCT_NAME="\"PHP php_imagick.dll\"" /d
THANKS_GUYS="\"Thanks to Mikko Koppanen, Scott MacVicar\"" win32\build\template.
rc
LIBC.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR
T.dll)
LIBC.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRT.lib(MSVC
RT.dll)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(ci
nitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(ci
nitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(ci
nitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(ci
nitexe.obj)
LIBC.lib(crt0dat.obj) : warning LNK4006: _exit already defined in MSVCRT.lib(MSV
CRT.dll); second definition ignored
LIBC.lib(crt0dat.obj) : warning LNK4006: __exit already defined in MSVCRT.lib(MS
VCRT.dll); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xc_z already defined in MSVCRT.lib(
cinitexe.obj); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xc_a already defined in MSVCRT.lib(
cinitexe.obj); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xi_z already defined in MSVCRT.lib(
cinitexe.obj); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xi_a already defined in MSVCRT.lib(
cinitexe.obj); second definition ignored
   Creating library Release_TS\php_imagick.lib and object Release_TS\php_imagick
.exp
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; us
e /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use
/NODEFAULTLIB:library
Release_TS\php_imagick.dll : fatal error LNK1169: one or more multiply defined s
ymbols found
NMAKE : fatal error U1077: '"cl.exe"' : return code '0x2'
Stop.
ImageMagick Multi Thread DLL
  • imagick will build fine as long as the PHP environment is setup properly.
  • Build seems to work fine on XP
  • Build will not work on Windows 2003, PHP loads the php_imagick.dll on startup and appears fine in phpinfo(), but when I test it I get the following:

Code: Select all

[Mon Mar 02 07:51:03 2009] [error] [client 127.0.0.1] PHP Fatal error:  Uncaught exception 'ImagickException' with message 'unable to open file `D:\\path\\to\\file\\test.png' @ png.c/unknown/2854' in D:\\path\\to\\file\\test.php:3\nStack trace:\n#0 D:\\path\\to\\file\\test.php(3): Imagick->__construct('test.png')\n#1 {main}\n  thrown in D:\\path\\to\\file\\test.php on line 3
With each ImageMagick build I copied the *.EXE and #.dll files to /php_build/bin, *.LIB files to /php_build/lib and all the header files for magick, Magick++ and wand to /php_build/include/magick, etc. before I build PHP with the --with-imagick=shared switch. I then copied the extention to my installed PHP ext folder and all the ImageMagick files to my installed ImageMagick folder, tested ImageMagick and then started Apache to see if the .dll loaded. If so, I then ran one of your examples from your site to test imagick.

As I said, the two builds where I can get imagick to build seem to work fine on Windows XP but when I copy the ImageMagick and imagick extention over to Windows 2003, Apache won't load the .dll or if it does load at start, imagick won't load an image. Here are the errors I get:

Code: Select all

PHP Warning:  PHP Startup: Unable to load dynamic library 'D:\\path\\to\\php\\ext\\php_imagick.dll' - Recursion too deep; the stack overflowed.\r\n in Unknown on line 0

Code: Select all

[Sat Feb 28 16:24:40 2009] [error] [client x.x.x.x] PHP Fatal error:  Uncaught exception 'ImagickException' with message 'unable to open file `D:\\path\\to\\file\\test.png' @ png.c/unknown/2854' in D:\\path\\to\\file\\test.php:4\nStack trace:\n#0 D:\\path\\to\\file\\test.php(4): Imagick->__construct('test.png')\n#1 {main}\n  thrown in D:\\path\\to\\file\\test.php on line 4
Any help here would be appreciated. BTW, I also tried the builds you have on your site and they won't work with ImageMagick 6.4.9-7 either so we are out of luck. :(
Mitron

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by Mitron »

Ok, while I'm not exactly sure what I did to fix this issue, I finally found a combination that works on both Windows XP and Windows 2003. I built this on Windows XP with Microsoft Visual C++ 6.0, ImageMagick-6.4.9-8 and PHP 5.2.9. I updated Visual C++ 6.0 to SP6 and Microsoft Platform SDK (February 2003).

ImageMagick-6.4.9-8.zip (source)
  • Unzip ImageMagick-6.4.9-8.zip to a work folder, i.e. C:\work so you have C:\work\ImageMagick-6.4.9-8
  • Load Visual C++ and open C:\work\ImageMagick-6.4.9-8\VisualMagick\configure\configure.dsw.
  • Right click "configure classes" and select "Set as Active Project".
  • Select Build, Set Active Configuration and click "configure -Win32 Release", OK.
  • Select Build, Build configure.exe
  • Select Execute configure.exe, Click Next
  • Select Static Multi-threaded DLL runtimes; Check Include all demo, test, appl, and contrib directories; Uncheck Generate Visual Studio 7 format; Click Next, Next, Finish
  • Load/Switch to Visual C++ and open C:\work\ImageMagick-6.4.9-8\VisualMagick\VisualStaticMTDLL.dsw
  • Right click "All classes" and select Set as Active Project
  • Select Build, Set Active Configuration and select All - Win32 Release, click OK
  • Select Build, Clean and then select Build, Build
The configure.exe builds with 0 errors and 1 warning and ImageMagick builds with 0 errors and 151 warnings.

PHP 5.2.9 (source, libs, binary-tools and T1_StaticMD.lib)
  • Unzip php-5.2.9.zip into the C:\work folder
  • Create a php_build folder in C:\work, so you have C:\work\php_build.
  • Unzip all Manditory PHP Libs and at least the jpeg and png libs into the php_build folder overwritting existing files.
  • Unzip T1_StaticMD.lib and the t1lib folder from PHP zip.zip file, into php_build\lib folder.
  • Unzip binary-tools.zip to php_build\ folder.
  • Extract imagick-2.2.2.tgz to C:\work\php-5.2.9\ext.
  • Rename C:\work\php_build\lib\libiconv_a.lib to C:\work\php_build\lib\inconv.lib.
  • Rename C:\work\php_build\lib\freetype_a.lib to C:\work\php_build\lib\freetype2.lib.
  • Copy your built ImageMagick files(\VisualMagick\bin\*, \VisualMagick\lib\*) to C:\work\php_build folder overwritting existing files.
  • Copy \magick, \wand \Magick++\lib\Magick++.h and \Magick++\lib\Magick++ to php_build\include folder.
  • Open a build environment command prompt (Windows 2003 Retail) or standard command prompt then set VC++ and php_build paths.
  • Change to your PHP source directory, i.e. cd C:\work\php-5.2.9 and enter the following:
  • buildconf
  • cscript /nologo configure.js --with-imagick
  • nmake
This will create the extention php_imagick.dll in the C:\work\php-5.2.9\Release folder. Simply move this to your PHP ext folder. You may also have to copy all the ImageMagick \bin\* files to your installed ImageMagick folder to make this work. It may also be possible to simply install the Static binary release of ImageMagick-6.4.9-8-Q16-windows-static.exe (I havent tried this yet). I just used the build.

I hope this helps someone and I'm hoping we will be able to get a working Dynamic build, but at least we can get going with a static build. If someone wants to try the static build I'm using, it seems to work with both Windows XP and Windows 2003 Server, feel free to PM me here and I'll give you a link.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by magick »

If you have a problem with the ImageMagick binary distributions, try downloading and installing the Microsoft Visual C++ 2008 Redistributable Package at http://www.microsoft.com/downloads/deta ... laylang=en.
Mitron

Re: Building php_imagick.dll from imagick-2.2.2.tgz

Post by Mitron »

Ok, it seems PHP 5.3.0 changed the build process. I am attempting to build the latest php_imagick.dll from 2.3.0 source using VC6, but of course I'm running into the same type of issues. I have a build that kind of works, it shows up in phpinfo() and it completes a couple tutorials on mikko's site, but I can't seem to get it to manipulate any images.

For instance his Typsetting and ImagickDraw tutorials work, but anything that has to do with existing images seems to fail. The strange thing is I'm getting absolutely no errors reported in the Apache error logs so this is a bit confusing. If I getting a working copy, I'll post the new procedure here.
Post Reply