Home  >  Article  >  Backend Development  >  PHP implements the method of synthesizing GIF images from JPG based on php_imagick_st-Q8.dll, _PHP tutorial

PHP implements the method of synthesizing GIF images from JPG based on php_imagick_st-Q8.dll, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:23:24847browse

PHP implements the method of synthesizing JPG into GIF images based on php_imagick_st-Q8.dll,

1. Overview:

This article explains in detail how PHP implements JPG synthesis of GIF images based on php_imagick_st-Q8.dll.
First, you need to implement PHP using 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 dynamic link library file in advance, configure the php.ini file, and enable php_imagick_st-Q8. .dll.

2. The configuration method is as follows:

1.

Put 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, that is:
extension=php_imagick_st-Q8.dll
3.
Restart apache or IIS.

3. The PHP implementation code is as follows:

<&#63;php
//定义JPG的图片序列
$filelist = array(
  '1.jpg',
  '2.jpg',
  '3.jpg',
  '4.jpg'
);
$type = 'gif';
$num = 200;
$qian = 'new_';
$path = './gif/';
$is = 1;
//生成gif图片的函数
get_img($filelist, $type, $num, $qian, $path, $is);
/*
 * get_img 图片合并,生成gif动态
 * $filelist 要合并的图片数组
 * $type 生成的类型
 * $num 生成的帧数
 * $qian 新文件名前缀
 * $path 保持路径
 * $is 是否预览
 */
function get_img($filelist, $type, $num, $qian, $path, $is)
{
 //初始化类
 $animation = new Imagick();
 //设置生成的格式
 $animation->setFormat($type);
 foreach ( $filelist as $file ){
 $image = new Imagick();
 $image->readImage( $file );  //合并图片
 $animation->addImage( $image ); //加入到对象
 $animation->setImageDelay($num); //设定图片帧数
 unset( $image );    //清除内存里的图像,释放内存
 }
 //以下两行是调试时用的,测试是否生成了gif图片
 //header( "Content-Type: image/gif" );
 //echo( $animation->getImagesBlob() );
 //生成的GIF文件名组合
 $images = $qian . time(). '.' . $type;
 //生成GIF图片
 $animation->writeImages( $images,true );
 //保存GIF到指定文件夹
 copy($images, $path . $images);
 //是否预览
 if($is)
 {
 echo '已生成gif图片: ' . $images . '<br />';
 echo "<img src='" . $path . $images . "' />";
 }
 else
 {
 echo '已生成gif图片: ' . $images . '<br />';
 }
 //删除原来保存的图片
 unlink($images);
}
&#63;>

http://www.bkjia.com/PHPjc/840631.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/840631.htmlTechArticlePHP implements the method of JPG synthesis of GIF images based on php_imagick_st-Q8.dll. 1. Overview: This article explains in detail the method of PHP based on php_imagick_st-Q8.dll php_imagick_st-Q8.dll implements the method of synthesizing JPG into GIF images. First of all, we must realize...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn