PHP uses the php_imagick_st-Q8.dll class library to connect the jpg image to generate GIF animated images, need to download the php_imagick_st-Q8.dll in advance, file, and configure the php. ini file to enable the php_imagick_st-Q8.dll. The configuration method is as follows:
1. Put the downloaded php_imagick_st-Q8.dll file to the default extension directory of PHP, that is: php/ext/directory;
2. Open php. ini and add a new line in the extension area. Note that there is no ";" in front of it.
Extension = php_imagick_st-Q8.dll
3. Restart apache or IIS.
4. PHP functions:
01
02 // define the JPG image sequence
03 $ filelist = array (
04 '1.jpg ',
05 '2.jpg ',
06 '3.jpg ',
07 '4.jpg'
08 );
09 $ type = 'gif ';
10 $ num = 200;
11 $ qian = 'new _';
12 $ path = './gif /';
13 $ is = 1;
14 // function for generating GIF images
15get_img ($ filelist, $ type, $ num, $ qian, $ path, $ is );
16 /*
17 * get_img image merging to generate gif Dynamics
18 * $ filelist: array of images to be merged
19 * $ type: type generated
20 * $ Number of frames generated by num
21 * $ qian new file name prefix
22 * $ path
23 * $ is preview?
24 */
25 function get_img ($ filelist, $ type, $ num, $ qian, $ path, $ is)
26 {
27 // initialization class
28 $ animation = new Imagick ();
29 // set the generated format
30 $ animation-> setFormat ($ type );
31 foreach ($ filelist as $ file ){
32 $ image = new Imagick ();
33 $ image-> readImage ($ file); // merge Images
34 $ animation-> addImage ($ image); // Add to object
35 $ animation-> setImageDelay ($ num); // you can specify the number of frames.
36 unset ($ image); // clear images in the memory and release the memory
37}
38 // The following two lines are used for debugging. test whether a GIF image is generated
39 // header ("Content-Type: image/gif ");
40 // echo ($ animation-> getImagesBlob ());
41 // a combination of GIF file names
42 $ images = $ qian. time (). '.'. $ type;
43 // generate a GIF Image
44 $ animation-> writeImages ($ images, true );
45 // Save the GIF to the specified folder
46 copy ($ images, $ path. $ images );
47 // whether to preview
48 if ($ is)
49 {
50 echo 'generated GIF image: '. $ images .'
';
51 echo"
";
52}
53 else
54 {
55 echo 'generated GIF image: '. $ images .'
';
56}
57 // Delete the saved Image
58 unlink ($ images );
59}
60?>