/*
圖片合并需要
1 下載 php_imagick_st-Q8.dll
并將其放入 php/ext/
2 在php.ini 中加入
extension=php_imagick_st-Q8.dll
重啟apache (web 服務(wù)器)
3 訪問phpinfo
*/
//參數(shù)設(shè)置
$filelist = array(
'1.jpg',
'2.jpg',
'3.jpg',
'4.jpg'
);
$type = 'gif';
$num = 200;
$qian = 'new_';
$path = './tupian/';
$is = 1;
//調(diào)用函數(shù)生成gif圖片
get_img($filelist, $type, $num, $qian, $path, $is);
/**
* get_img 圖片合并,生成gif動態(tài)
*
* $filelist 要合并的圖片數(shù)組
* $type 生成的類型
* $num 生成的幀數(shù)
* $qian 新文件名前綴
* $path 保持路徑
* $is 是否預(yù)覽
*
*/
function get_img($filelist, $type, $num, $qian, $path, $is)
{
//初始化類
$animation = new Imagick();
//設(shè)置生成的格式
$animation->setFormat($type);
foreach ( $filelist as $file ){
$image = new Imagick();
$image->readImage( $file ); //合并圖片
$animation->addImage( $image ); //加入到剛才建立的對象
$animation->setImageDelay($num); //設(shè)定圖片的幀數(shù)
unset( $image ); //消除內(nèi)存里的圖像資源
}
//調(diào)試是否生成gif圖片
//header( "Content-Type: image/gif" );
//echo( $animation->getImagesBlob() );
//新圖片文件名組合
$images = $qian . time(). '.' . $type;
//生成圖片
$animation->writeImages( $images,true );
//保存都指定目錄
copy($images, $path . $images);
//是否預(yù)覽
if($is)
{
echo '已生成gif圖片: ' . $images . '<br />';
echo "<img src='" . $path . $images . "' />";
}
else
{
echo '已生成gif圖片: ' . $images . '<br />';
}
//刪除最先保存的圖片
unlink($images);
}