Php code for generating gif dynamic images from multiple jpg images

Source: Internet
Author: User
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 );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.