7

I am trying to use iMagick in Symfony2.

I am using PHP 5.4.16 and all i have done :

1-Copy php_imagick_nts.dll from php5-4 directory from the extracted http://valokuva.org/~mikko/imagick-php54-php53.tgz to php/ext .

2-Rename it to php_imagick.dll and add the “extension=php_imagick.dll” to php.ini

3-Create a page like this :

<?php 
    $a = new Imagick();
?>

but i receive this :

Fatal error: Class ‘Imagick’ not found in C:\xampp\htdocs\info.php

When I tried to use this in a symfony controller, the error occur again:

FatalErrorException: Error: Class 'Imagick' not found

Unfortunately the details about imagick extension not appear in output of "phpinfo()"

Is this version is incompatible with PHP 5.4.16 ?! If yes,what version i must use? Where? Thank for any help...

ABS
  • 2,626
  • 3
  • 28
  • 44
  • 1
    Did you restart the server and PHP before trying? – Paul Denisevich Aug 22 '13 at 08:23
  • Just make sure you have `Visual C++ Redistributable Package` installed on your computer (https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170). It solved my issue. – Mher Feb 16 '22 at 17:05

7 Answers7

12

After trying many solutions, none seemed to work.

I managed to install it on Windows 10 64-bit, Apache 2.4 and PHP 5.6, but I think it should work for all versions.

Hopefully you will have no problem installing Imagick for PHP.


Step 1) Gather information

First of all you should gather some information of your PHP environment.

You can easily see your PHP information with the function phpinfo()

The information you need:

  • Architecture: x86(32-bit) or x64(64-bit)
  • PHP-version: you can find this in the header of the phpinfo() output.
  • PHP Extension Build: This string contains 2 important parts:
    • NTS or TS
    • VCx (like VC11)
  • Loaded Configuration File: the path to your used php.ini file.

Step 2) Download Binary

You can download the binary from the official site of ImageMagick. I recommend you to read the small introduction under the "Windows Binary Release" to be certain which "bits-per-pixel" to choose from(8 or 16). Downloading the latest version should be just fine.

Make sure this binary is the same architecture as your PHP architecture that you have gathered in step 1.

Step 3) Install Binary

Install the binary to your phpx.x.xx\bin file. For example: C:\wamp64\bin\php\php5.6.16\bin. (This can be any folder, but for the convenience I put in here)

Make sure "Add application directory to your system path" is checked. Should be checked by default though.

Step 4) Download PHP extension

The DLL PHP extension is available through the windows pecl php site

Again, you can just click the latest version.

Next of, choose the right version based on the gathered information.
For example: php_imagick-3.4.1-5.6-nts-vc11-x64.zip

This can be stripped into components:

  • php_imagick-3.4.1 - This is the php imagick extension with the version. This is not important.
  • 5.6 - This is your PHP version and should be equal to the PHP-version you are using, which you have determed in step 1.
  • NTS - This should be equal to the information of your PHP Extension Build that you have gathered in step 1.
  • VC11 - This should also be equal to the information of your PHP Extension Build that you have gathered in step 1.
  • x64 - This the architecture of the extension and should be equal to your PHP architecture that you have gathered in step 1.

Step 5) Extract PHP Extension

After you have downloaded the file, you should open the .zip file and look for a file named: php_imagick.dll. Extract this file to phpx.x.xx\ext.

Make sure the .dll file is fully accessable by you. Sometimes you need to explicity unblock the file.

Unblock file

Step 6) Activate PHP extension

To activate the extension in PHP, you should state in your php.ini file that you want to use this extension. You have gathered the path to your used php.ini file in step 1.

Add the line extension=php_imagick.dll to your php.ini

PHP.ini Imagick line

Step 7) Restart your PC

Just to make sure, restart your PC so all Environment Paths will be correctly loaded.


This should install Imagick correctly with the latest versions and the right architecture. Imagick should also be listed in phpinfo() with the appropriate "ImageMagick supported formats" (Just make sure it is not empty).

nkmol
  • 8,025
  • 3
  • 30
  • 51
  • 1
    Excellent directions...still working on getting them to work, but the windows download directory on the ImageMagick website is actually http://www.imagemagick.org/script/download.php#windows, NOT http://www.imagemagick.org/script/script/download.php#windows (extra script dir) – Stan Quinn Dec 18 '17 at 05:42
  • This answer was most helpful after 2 hours of trying many answers on stack overflow. I am currently getting a notice that the version imagick was compiled against is older than the one loaded. 1799 vs 1803 which is not even the version numbers that correlates to the website but at least I got my composer update command to install the library I was looking to use. – Neo May 04 '21 at 20:39
  • Perfect. I followed most of these directions from other sources, but the one thing that everyone else failed to mention (except you!) is the unblock part. I'm not sure why nobody writes full instructions like this, especially on the official websites. – Studocwho Jan 28 '23 at 05:33
10

I spent many hours trying to make Imagick work, finally I got it.

My installation instructions

  1. Install WAMP 32bit (even if you running 64bit system you must use 32bit version of WAMP)
  2. Install ImageMagick to C:/imagemagick, use this file: https://www.dropbox.com/s/i2mhrhd7sp0ilzk/ImageMagick-6.8.0-3-Q16-windows-dll.exe
  3. Put DLL with Imagick into extension folder of PHP, e.g. D:\wamp32\bin\php\php5.4.16\ext, I used this file: https://www.dropbox.com/s/ayankf850l08rm2/php_imagick.dll
  4. In php.ini put line "SetEnv MAGICK_HOME C:/imagemagick" without quotes
  5. Better restart PC

I use Wamp 2.4, PHP 5.4.16, Apache 2.4.4, ImageMagick 6.8.0-3 2012-10-24 Q16, Imagick 3.1.0RC2 - all 32bit, OS Win8 64bit

Now it should work and you should see Imagick extension loaded in phpinfo.

I tried a lot of versions of ImageMagick, but newer versions didn't work, 6.8.0-3-Q16-windows-dll works fine.

Symfony2

In Symfony2 use Imagick like this:

$im = new \Imagick('image.jpg');
fmstoun
  • 238
  • 4
  • 13
  • Thanks. It worked for me in one try, tried a lot of other versions which didn't worked. – Minion Feb 02 '14 at 17:43
  • This does not work on my Win 7, 64-bit system (using all 32-bit binaries). I've rebooted, checked path for IM duplicates, etc. I've re-installed multiple times (both WAMP & IM). – Dan Mar 27 '14 at 00:56
  • 2
    php.ini should have `extension=php_imagick.dll` I don't think the `SetEnv` is needed. – Blake Erickson Aug 08 '14 at 18:34
2

I'm quite sure this is to do with not having the module loaded correctly or the .dll being placed in a improper location.

You can use PHP's internal function extension_loaded() to check prior to using the class,

<?php
  /**
   * 
  **/
  if (!extension_loaded('Imagick')) {
        //Load some error.
  }
?>

That's a method you can check if the module is even being reconsigned by PHP at all. PHP also provides a function to view your current extensions get_loaded_extensions():

<?php 
   /**
    *   Get an Array of current
    *   PHP extensions for debugging
   **/
   print_r( get_loaded_extensions() );
?>

Make sure you do:

  • Check your correct extension library folder location within your phpinfo()
  • Perform a hard restart of your xmapp/wamp server.
  • If you're on PHP 5.4 or upwards (Like yourself!), see site below for the updated binaries

After researching too, Imagick does seem to have trouble with PHP 5.3 or upwards; Download new DLL's from this site below (Unofficial):

http://www.peewit.fr/imagick/

Also found other StackOverFlow Articles that have the same problem:

Stackoverflow: Trying to get imagick running on PHP 5.4.3 at Windows x64

Alternatively you're able to use the GD extension to more or less accomplish some of the same functions you require. I do believe GD is a more widely supported module/extension in more recent versions of PHP.

Community
  • 1
  • 1
MackieeE
  • 11,751
  • 4
  • 39
  • 56
  • Thanks for your response MackieeE, but not solved. I put it in correct folder. To ensure, i test your code( if (!extension_loaded('Imagick')) ) with another extension and worked! I also checked again php.ini for any wrongs,but there is no wrong line! Whats the problem you think? – ABS Aug 22 '13 at 09:41
  • @AliBagheriShakib Well - you're not the only one it seems :) I've found other pages with the same issue, although they are probably something that you've found too.. :| – MackieeE Aug 22 '13 at 10:30
  • Hi @MackieeE. Is it necessary to install http://www.imagemagick.org/download/binaries/ImageMagick-6.8.6-8-Q16-x86-dll.exe ? Or copy the dll file in extensions dir is sufficient? – ABS Aug 22 '13 at 10:33
  • If you installed the binaries via the .exe, did you include them into your PATH? – MackieeE Aug 22 '13 at 11:13
  • Another page: http://alexdespaindev.blogspot.co.uk/2012/02/wamp-server-and-imagemagick.html - Also, apologies that I've not been able to provide a definitive answer :/ – MackieeE Aug 22 '13 at 11:14
  • No, I copy them manually to xampp/php/ext folder. Yeah,it look like there is no clear way to use iMagick properly with PHP 5.4 on Apache. Many users compile and release different compiles of ImageMagick and i test many of them,but not worked for me :( – ABS Aug 22 '13 at 12:30
  • @AliBagheriShakib Well, you could alternatively use GD - that module should do most of the same functions as magik? – MackieeE Aug 22 '13 at 12:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36010/discussion-between-ali-bagheri-shakib-and-mackieee) – ABS Aug 22 '13 at 13:05
1

For those using Windows 10 with PHP 7 the following might help:

  • determine whether your Windows is threadsafe (see the output of phpinfo()) and 32 or 64 bits.
  • This page contains matching sets for each php version and threadsafe and 32/64 settings. Download both the Imagick and the Imagemagick files.
  • Follow for Imagick the instructions at the bottom of that page.
  • For ImageMagick the instructions on that page are not correct. You can put the dll files anywhere but you need to refer to them with the MAGICK_HOME windows environment variable. You may need to reboot for the change of the environment to have effect.
user2587656
  • 309
  • 3
  • 5
0

I use :Wamp 2.4, PHP 5.4.16, Apache 2.4.4, ImageMagick 6.8.0-3 2012-10-24 Q16, Imagick 3.1.0RC2 - all 32bit, OS Win7 32bit

Instructions given by fmstoun worked for me perfectly. Since I spent a lot of hours trying to make the dll work, I wanted to add on to steps given by fmstoun.

  • Do restart your PC.
  • Use the full path to the image, for example:
$image = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/test.jpg');
  • Make sure your system environment has 1 single entry for : C:/imagemagick and no more environment variables for imagemagick. If any previous installations have the path, then remove those paths and restart your PC
  • Make sure
    http : / / localhost/
    of wamp shows 'imagick' as loaded extension
  • If extension is loaded properly, it has to show up in phpinfo() also as:
  • imagick module  | enabled
  • ImageMagick version|ImageMagick 6.8.0-3 2012-10-24 Q16 
    and some more information about imagemagick.

Considering the date of this post, the latest version of imagemagick provided on the official site is: ImageMagick-6.8.8-1-Q16-x86-dll.exe which fails to load the extension (as seen in apache error logs after a restart). Hence use the version mentioned by fmstoun.

Hope this answer saves couple of hours of effort and saves time required to go through around 15 SO questions on same topic and also different forums.

learner
  • 128
  • 1
  • 9
0

UPDATE for those 2019 also using WAMP, a much more simplier method of ImageMagick are as follows:

  1. Go to https://mlocati.github.io/articles/php-windows-imagick.html.
  2. Grab a copy of the .dll extension file of your appropriate setup, choose a "Threads Safe" version.
  3. Grab the corresponding ImageMagick using the link on the same row and install it.
  4. Copy only the .dll file to the extensions folder of your install of WAMP, usually C:\wamp\bin\apache2.4\ext\
  5. Restart apache.

Hope this helps.

Jason
  • 64
  • 1
  • 3
-2

Sorry for my bad english:

1º Install Appserv

Filename: "appserv-win32-2.5.10.exe"

URL download: h*ttp://www.appservnetwork.com/ (without *)

Apache port: 8080

2º Download PHP 5.3(Apache 2.2 doesn't support superior)

Filename: "php-5.3.29-Win32-VC9-x86.zip"

How?: Thread Safe

URL Download: h*ttp://windows.php.net/download#php-5.6 (without *)

3º Stop Apache

4º Delete all contents in the folder "..\AppServ\php5"

5º Copy the zip contents to "..\AppServ\php5"

6º Add line

date.timezone = "America/Buenos_Aires" (This is my zone, find yours in php page)

to the "php.ini" in "c:\Windows\php.ini"

to avoid date error in PHP

7º Start Apache

=============================

IMAGIC(Once PHP 5.3 is installed)

1º Instalññ Image magic 6.7(Not superior, PHP 5.3 doesn't support)

Filename: "ImageMagick-6.7.9-9-Q16-windows-dll.exe"

URL download: http://ftp.icm.edu.pl/packages/ImageMagick/binaries/

2º Download Imagic

Filename: "php_imagick-3.1.2-5.3-ts-vc9-x86.zip"

URL download: http://windows.php.net/downloads/pecl/releases/imagick/3.1.2/

3º In the dir "php5/ext" add the file "php_imagick.dll" from the last zip download(other files doesn't care)

4º Add line

extension=php_imagick.dll

to the "php.ini" in "c:\Windows\php.ini"

5º Restart Apache

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
lucasgabmoreno
  • 1,001
  • 1
  • 10
  • 18