PHP uses JPG to generate GIF animated pictures

Source: Internet
Author: User
Tags ini

PHP uses the Php_imagick_st-q8.dll class library, the JPG picture connection produces the GIF animation picture, needs to download the good Php_imagick_st-q8.dll, the file beforehand, and configures PHP.ini file, enables Php_imagick_ St-q8.dll. The configuration method is as follows:

1, will download the Php_imagick_st-q8.dll file to the PHP default extension directory, namely: php/ext/directory;

2, open php.ini, in the extension area new join this trip, pay attention to the front do not have ";"

Extension=php_imagick_st-q8.dll

3, restart Apache or IIS.

4, the PHP function is as follows:

01

02//defines a picture sequence for jpg

03$filelist = Array (

' 1.jpg ',

' 2.jpg ',

' 3.jpg ',

Modified ' 4.jpg '

08);

09$type = ' gif ';

10$num = 200;

11$qian = ' New_ ';

12$path = './gif/';

13$is = 1;

14//functions to generate GIF pictures

15get_img ($filelist, $type, $num, $qian, $path, $is);

16/*

* get_img picture Merge, generate GIF dynamic

* $filelist An array of pictures to merge

Type of * $type generated

Number of frames generated by $num

* $qian new filename prefix

* $path Keep the path

* $is whether to preview

24 */

25function get_img ($filelist, $type, $num, $qian, $path, $is)

069

27//Initialization class

$animation = new Imagick ();

29//Set the generated format

$animation->setformat ($type);

foreach ($filelist as $file) {

$image = new Imagick ();

$image->readimage ($file); Merging pictures

$animation->addimage ($image); Add to Object

$animation->setimagedelay ($num); Set Picture frame number

Unset ($image); Clears the image in memory and frees up memory

37}

38//The following two lines are used for debugging, testing whether to generate a GIF picture

//header ("Content-type:image/gif");

//echo ($animation->getimagesblob ());

41//generated GIF file name combination

$images = $qian. Time (). '.' . $type;

43//GIF image generation

$animation->writeimages ($images, true);

45//Save GIF to specified folder

Copy ($images, $path. $images);

47//Whether preview

if ($is)

49 {

Echo ' has generated a GIF picture: '. $images. '

';

' Echo '


";

52}

Or else

54 {

Echo ' has generated a GIF picture: '. $images. '

';

56}

57//Delete original saved picture

Unlink ($images);

59}

60?>

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.