First step, install ImageMagick
You first need to install ImageMagick because Imagick is a PHP extension that can be used by PHP to invoke ImageMagick functionality. (Currently the latest version is: Imagemagick-6.8.9-5-q16-x64-dll.exe)
Installation directory can not have spaces, I personally is installed in the C packing directory:
C:\ImageMagick
All the way to the default installation, after installation, open the CMD command line interface, enter:convert , and press ENTER, if you can see a lot of content is the installation success.
If you are prompted to "convert is not an internal or external command, a program or batch file that can be run," or "Enter the drive letter of the conversion" (convert is a default system command that converts FAT32 to NTFS) then you need to ImageMagick Add the installation path to the system path.
---Right--click Properties---------------------------------"Path"--Select and click Edit--Add your installation
Step two, install Imagick
Click here to download, note that when downloading the corresponding PHP version, and note whether the system is 32-bit or 64-bit, and PHP is NTS version or TS version (currently the latest stable version is 3.1.2, about how to determine whether PHP is NTS version or TS version, you can phpinfo view its The Thread Safety item in, if it is enabled on behalf of the TS version, no is the NTS version)
Unzip the downloaded package, locate the Php_imagick.dll file, put it in the PHP extension directory, then open the php.ini file and add the following line to the corresponding location:
Extension=Php_imagick. DLL
Save and restart your computer to make sure it takes effect.
Step three, check
If everything is OK, you should see Imagick in phpinfo after reboot, such as:
If not, return to the first step and replace the different versions of ImageMagick to reinstall and re-debug.
Fourth step, test
OK, to this step can begin to write code, the process is not elaborate, directly on the code
Error_reporting (E_error | e_warning); $im = new Imagick (' 1.psd '); $im->setimageindex (0); $im->setiteratorindex (0); $im->stripimage (); Removal of picture information $im->setimagecompressionquality (80); Image quality $im->writeimage (' 1.jpg ');
The above code has been tested to produce a 1.jpg image correctly.
Suggested thumbnails or JPG format, because the PNG format does not support compression, I am testing the use of 30M PSD file, generated PNG thumbnail has more than 3M, and JPG only 200KB, and the speed of the PNG image is obviously very slow, it takes about 3, 4 seconds.
In addition to do the extreme test, with a nearly 600M PSD file generated jpg thumbnail, the speed of the basic in 2 seconds, the file size of less than 2.5M, because the image is not resized, so the final volume of the resulting file can be reduced according to the actual situation.
Appendix:
1. PHP Image processing Library ImageMagick installation under Windows
2, Php+imagick the operation of the PSD file
3. Imagick Official documents