PHP uses the php_imagick_st-Q8.dll class library to connect JPG images to generate GIF animated images. You need to download the php_imagick_st-Q8.dll file in advance, configure the php.ini file, and enable php_imagick_st-Q8.dll. . The configuration method is as follows:
1. Place the downloaded php_imagick_st-Q8.dll file into the PHP default extension directory, which is: php/ext/ directory;
2. Open php.ini and add this line in the extension area. Be careful not to have ";" in front of it
extension=php_imagick_st-Q8.dll
3. Restart apache or IIS.
4. The PHP function is as follows:
01
02//Define 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 to generate gif images
15get_img($filelist, $type, $num, $qian, $path, $is);
16/*
17 * get_img merges images and generates dynamic gif
18 * $filelist Image array to be merged
19 * $type generated type
20 * $num Number of frames generated
21 * $qian new file name prefix
22 * $path maintain path
23 * $is whether to preview
24 */
25function 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); //Set the number of picture frames
36 unset( $image ); //Clear the image in the memory and release the memory
37}
38 //The following two lines are used for debugging to test whether a gif image is generated
39 //header( "Content-Type: image/gif" );
40 //echo( $animation->getImagesBlob() );
41 //Generated GIF file name combination
42 $images = $qian . time(). '.' . $type;
43 //Generate 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 original saved picture
58 unlink($images);
59}
60?>