ImageMagick is like the photoshop on your console demand. Best with their explanation.
ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
It is very powerful and supports all platforms with tons of different languages and implementations. I always used awesome GD library to process images on my projects. Now i am going to use it so I needed to install it to my development environment which is windows 10. I am going to install and use Imagick also because using IM from native PHP is much more faster than using it from console via exec.
Well first of all ImageMagick on windows with PHP is a really pain in the ass, if you have the commitment and time go for it otherwise use it from console. Here are the steps and todo’s to install for PHP 5.6.x.
Just to make things clear, all the PHP dll files (librarires) are 32 bit, so if your system is 64 bit and you will still need to download and operate 32 bit ImageMagick, Apache, etc.
Download ImageMagick
Download the latest version, which is Win32 dynamic at 16 bits-per-pixel
Now the beauty, static versions are suppose to work with every platform but they act really funny so you should download a dynamic version. If you system/pc supports go for 16 bit Q16. The difference is explained on the link very well.
I suggest you to download and try the latest one, complete all steps, if it doesn’t work try with a lower version and so on.
Install ImageMagick
Install the ImageMagick on a path like C:\imagemagick\ with no spaces and simple location. Do not go for c:\program files\etc
Do not forget to click on the “Add to system path” check-box. You can ignore the rest of the check-boxes
Test the Installation
Open the command prompt (Run->”CMD”->ENTER) and type in convert and press enter. You should see the help parameters of convert. If so go to next step.
if it says its failed or unknown function or type in a parameter to convert ( which is a default function in Windows XP to convert HDD from FAT32 to NTFS or vice varsa ) you need to add path to environment by yourself.
My Computer -> Right Click -> Properties -> Advanced (Tab) -> Environment Variables (at the bottom) -> System Variables (Section) -> Scroll to Find “Path” -> Select it and click Edit -> Add your installation directory to there i.e. “C:\ImageMagick;”.
Downloading the php_Imagick.dll
Again the version problem, well if you are using PHP 5.6.x download your dll.
dyn = dynamic, st = static, q16 = 16 bit, q8= 8 bit. This should match your downloaded version of course. If you downloaded q16 dynamic library, your file will be php_imagick_dyn-Q16.dll
Find and Place the dll in your extension folder
Rename the downloaded dll to php_imagick.dll for easy usage and place it under your extension folder. It is usually “php/ext/” and “D:\xampp\php\ext” for XAMPP.
If it is not, then you can find it in your php.ini file with the extension_dir param.
; Directory in which the loadable extensions (modules) reside.
extension_dir = “Something something”
Edit PHP.ini
Uncomment if it exists or add if it doesn’t exist this line
extension=php_imagick.dll
Restart
This is the important part, you need to restart your PC to libraries take effect.
If you do not restart and start your Apache you will see an error. So please do restart your PC.
Start Apache and check
Start your Apache, and check with the phpinfo() , if you see imagick library and its values that’s it you are set.
If not you have picked up the wrong dll file for PHP. Browse through the directory and try another dlls, if they don’t work try to lower your ImageMagick installation version. Don’t give up, it will work.
Test with some code
Put a nice big picture named demo.jpg along side with your demo.php script, run the test and check the directory to see thumb.jpg. Here is the script, simple and fast 🙂
1 2 3 4 5 6 7 |
< ?php $im = new imagick( 'demo.jpg' ); // resize by 200 width and keep the ratio $im->thumbnailImage( 200, 0); // write to disk $im->writeImage( 'thumb.jpg' ); ?> |
Conclusion
So this is it, I hope you get it to work at the first trial now and drop a comment if you have any useful information or experience any error, we will try to help you out.