First, overview:
This article describes the PHP based on php_imagick_st-q8.dll implementation of JPG GIF image synthesis method.
First of all to implement PHP using the Php_imagick_st-q8.dll class library, the JPG image connection to generate GIF animated pictures, you need to download the Php_imagick_st-q8.dll dynamic link library files, and configure php.ini files, enable PHP _imagick_st-q8.dll.
Second, the configuration method is as follows:
1, will download the Php_imagick_st-q8.dll file to the PHP default extension directory, namely: php/ext/directory ;
2, open php.ini, in the extension area new join this trip, pay attention to the front do not have ";", namely:
Extension=php_imagick_st-q8.dll
3, restart Apache or IIS.
Three, the PHP implementation code is as follows:
<?php//define JPG's picture sequence $filelist = Array (' 1.jpg ', ' 2.jpg ', ' 3.jpg ', ' 4.jpg ');
$type = ' gif ';
$num = 200;
$qian = ' New_ ';
$path = './gif/';
$is = 1;
Functions that generate GIF images get_img ($filelist, $type, $num, $qian, $path, $is); * * get_img picture merge, generate GIF dynamic * $filelist an array of pictures to merge * $type generated type * $num number of frames generated * $qian new filename prefix * $path keep path * $is Preview *
/function Get_img ($filelist, $type, $num, $qian, $path, $is) {//Initialize class $animation = new Imagick ();
Sets the generated format $animation->setformat ($type);
foreach ($filelist as $file) {$image = new Imagick (); $image->readimage ($file); Merge pictures $animation->addimage ($image); Add to Object $animation->setimagedelay ($num); Set Picture frame number unset ($image);
Clear the memory of the image, free memory}//The following two lines are used for debugging, test whether the generated GIF image//header ("Content-type:image/gif");
Echo ($animation->getimagesblob ()); The generated GIF file name combination $images = $qian. Time (). '.' .
$type;
Generates a GIF picture $animation->writeimages ($images, true);
Save GIF to the specified folder copy ($images, $path. $images); Whether to preview if ($is) {echo ' has generated a GIF picture: '. $images.
' <br/> '; echo " ';
//Delete the original saved picture unlink ($images); }?>