PHP uses the Php_imagick_st-q8.dll class library, the JPG picture connection produces the GIF animation picture, needs to download the good Php_imagick_st-q8.dll, the file beforehand, and configures PHP.ini file, enables Php_imagick_ St-q8.dll. 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 ";"
Extension=php_imagick_st-q8.dll
3, restart Apache or IIS.
4, the PHP function is as follows:
01
02//defines a picture sequence for jpg
03$filelist = Array (
' 1.jpg ',
' 2.jpg ',
' 3.jpg ',
Modified ' 4.jpg '
08);
09$type = ' gif ';
10$num = 200;
11$qian = ' New_ ';
12$path = './gif/';
13$is = 1;
14//functions to generate GIF pictures
15get_img ($filelist, $type, $num, $qian, $path, $is);
16/*
* get_img picture Merge, generate GIF dynamic
* $filelist An array of pictures to merge
Type of * $type generated
Number of frames generated by $num
* $qian new filename prefix
* $path Keep the path
* $is whether to preview
24 */
25function get_img ($filelist, $type, $num, $qian, $path, $is)
069
27//Initialization class
$animation = new Imagick ();
29//Set the generated format
$animation->setformat ($type);
foreach ($filelist as $file) {
$image = new Imagick ();
$image->readimage ($file); Merging pictures
$animation->addimage ($image); Add to Object
$animation->setimagedelay ($num); Set Picture frame number
Unset ($image); Clears the image in memory and frees up memory
37}
38//The following two lines are used for debugging, testing whether to generate a GIF picture
//header ("Content-type:image/gif");
//echo ($animation->getimagesblob ());
41//generated GIF file name combination
$images = $qian. Time (). '.' . $type;
43//GIF image generation
$animation->writeimages ($images, true);
45//Save GIF to specified folder
Copy ($images, $path. $images);
47//Whether preview
if ($is)
49 {
Echo ' has generated a GIF picture: '. $images. '
';
' Echo '
";
52}
Or else
54 {
Echo ' has generated a GIF picture: '. $images. '
';
56}
57//Delete original saved picture
Unlink ($images);
59}
60?>