Php code for generating gif dynamic images from multiple jpg images
/*
Image merging needs
1 download php_imagick_st-Q8.dll
And put it in php/ext/
2 Add in php. ini
Extension = php_imagick_st-Q8.dll
Restart apache (web server)
3. access phpinfo
*/
/*
Image merging needs
1 download php_imagick_st-Q8.dll
And put it in php/ext/
2 Add in php. ini
Extension = php_imagick_st-Q8.dll
Restart apache (web server)
3. access phpinfo
*/
// Parameter settings
$ Filelist = array (
'1.jpg ',
'2.jpg ',
'3.jpg ',
'4.jpg'
);
$ Type = 'GIF ';
$ Num = 200;
$ Qian = 'new _';
$ Path = './tupian /';
$ Is = 1;
// Call the function to generate a GIF image
Get_img ($ filelist, $ type, $ num, $ qian, $ path, $ is );
/**
* Get_img merge images to generate gif dynamics
*
* $ Filelist: array of images to be merged
* $ Type: type generated
* $ Number of frames generated by num
* $ Qian new file name prefix
* $ Path
* $ Is preview?
*
*/
Function get_img ($ filelist, $ type, $ num, $ qian, $ path, $ is)
{
// Initialization class
$ Animation = new Imagick ();
// Set the generated format
$ Animation-> setFormat ($ type );
Foreach ($ filelist as $ file ){
$ Image = new Imagick ();
$ Image-> readImage ($ file); // merge images
$ Animation-> addImage ($ image); // add the object you just created
$ Animation-> setImageDelay ($ num); // you can specify the number of frames for an image.
Unset ($ image); // eliminates image resources in the memory.
}
// Debug whether to generate a GIF image
// Header ("Content-Type: image/gif ");
// Echo ($ animation-> getImagesBlob ());
// New image file name combination
$ Images = $ qian. time (). '.'. $ type;
// Generate an image
$ Animation-> writeImages ($ images, true );
// Specify the directory for saving
Copy ($ images, $ path. $ images );
// Whether to preview
If ($ is)
{
Echo 'generated GIF image: '. $ images .'
';
Echo "";
}
Else
{
Echo 'generated GIF image: '. $ images .'
';
}
// Delete the first saved image
Unlink ($ images );
}