PHP using Imagick generated psd file thumbnail tutorial,
First step, install ImageMagick
First, you need to install ImageMagick http://imagemagick.org/script/binary-releases.php#windows, because Imagick is a PHP call ImageMagick Features of PHP extensions. (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:
Copy the Code code as follows:
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:
Copy the Code code as follows:
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
Copy the Code code as follows:
Error_reporting (E_error | e_warning);
$im = new Imagick (' 1.psd ');
$im->setimageindex (0);
$im->setiteratorindex (0);
$im->stripimage (); Remove picture information
$im->setimagecompressionquality (80); Picture 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.
Fifth step, other formats
In addition to the PSD file, I also tried some other formats, such as MP4, AVI and other video formats, but the production speed is super slow. Finally found that the more practical is to generate thumbnails of PDF files, but before processing the PDF file, you need to install Ghostscript, and then the overall code is basically the same as the code generated PSD
Copy the Code code as follows:
$im = new Imagick ();
$im->readimage (' d:/soft/wamp/www/test/1.pdf[0] ');
echo $im->getnumberimages ();
$im->writeimages (' d:/soft/wamp/www/test/1.jpg ', false);
http://www.bkjia.com/PHPjc/947925.html www.bkjia.com true http://www.bkjia.com/PHPjc/947925.html techarticle PHP using Imagick generated psd file thumbnail tutorial, the first step, installation ImageMagick first need to install ImageMagick http://imagemagick.org/script/ Binary-releases.php#windows, because ...