PHP uses JPG to generate GIF animated images. PHP uses the php_imagick_st-Q8.dll class library, the jpg image connection to generate GIF animated images, need to download the php_imagick_st-Q8.dll, file, and configure php. ini file, enable php_imagick_st PHP to use the php_imagick_st-Q8.dll class library, the jpg image connection to generate GIF animated images, need to download the php_imagick_st-Q8.dll, file, and configure php. ini file to enable 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?>
...