国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP使用GIFEncoder類處理gif圖片實(shí)例

2020-03-22 20:15:57
字體:
供稿:網(wǎng)友
下面貼處理的源代碼:
復(fù)制代碼 代碼如下:
php
require_once("gifencoder.php"); //載入編碼 文件
$gif = new GIFEncoder(); //實(shí)例化gif解碼對象
$gif- load("test.gif"); //載入要解碼的gif圖像
for($i=0;$i sizeof($gif- IMGS["frames"]);$i++){ //根據(jù) gif圖像的幀數(shù)獲取每幀的圖像數(shù)據(jù)
$im = imagecreatefromstring($gif- getgif($i)); //利用GD庫函數(shù)將GIF轉(zhuǎn)得標(biāo)準(zhǔn)些
imagegif($im, $i.".gif"); //用文件形式保存生成的每幀圖像數(shù)據(jù),當(dāng)然也可以用變量
}
imagedestroy($im);
ob_start();
for($i=0;sizeof($gif- IMGS["frames"]);$i++){
$im=imagecreatefromgif("0.gif"); //根據(jù)每幀的圖片創(chuàng)建圖像
if($i 0){ //不是第一幀 復(fù)制圖片和第一幀合并
$frame=imagecreatefromgif("$i.gif"); //讀取當(dāng)前幀的圖像
$w = imagesx($frame); //獲取圖像寬度
$y= imagesy($frame); //獲取圖像高度
imagecopy($im,$frame,0,0,0,0,$w,$y); //把當(dāng)前幀圖像和第一幀圖像復(fù)制合并
imagedestroy($frame); //銷毀當(dāng)前圖像
}
imagejpeg($im,$i."frame.jpg"); //合并后保存為jpg格式
$im=imagecreatefromjpeg($i."frame.jpg"); //從jpg格式重新創(chuàng)建圖像
imagegif($im); //轉(zhuǎn)為gif格式
imagedestroy($im); //銷毀圖像
$imagedata[] = ob_get_contents(); //創(chuàng)建這一幀的圖像數(shù)據(jù)
ob_clean();
}
$diy[]=0;//開始延遲時間
$gif = new GIFEncoder($imagedata,$diy,0,2,0,0,0,"bin"); //實(shí)例化gif編碼對象
ob_start();
Header ('Content-type:image/gif');
echo $gif- GetAnimation();

以上代碼 基本就是一個完整的 讀取一個gif圖片,對其進(jìn)行解碼,然后再編碼成gif圖片的完整過程了..
有了這個就可以在網(wǎng)上隨意抓取gif圖片然后進(jìn)行修改。甚至直接用php就可以自己制作一些gif圖片.GIFEncoder類源碼:
復(fù)制代碼 代碼如下: php
Class GIFEncoder {
var $GIF = "GIF89a"; /* GIF header 6 bytes */
var $VER = "GIFEncoder V2.06"; /* Encoder version */
var $BUF = Array ( );
var $LOP = 0;
var $DIS = 2;
var $COL = -1;
var $IMG = -1;
var $ERR = Array (
'ERR00' = "Does not supported function for only one image!",
'ERR01' = "Source is not a GIF image!",
'ERR02' = "Unintelligible flag ",
'ERR03' = "Could not make animation from animated GIF source",
);
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFEncoder...
::
*/
function GIFEncoder (
$GIF_src, $GIF_dly, $GIF_lop, $GIF_dis,
$GIF_red, $GIF_grn, $GIF_blu, $GIF_mod
) {
if ( ! is_array ( $GIF_src ) && ! is_array ( $GIF_tim ) ) {
printf ( "%s: %s", $this- VER, $this- ERR [ 'ERR00' ] );
exit ( 0 );
}
$this- LOP = ( $GIF_lop -1 ) $GIF_lop : 0;
$this- DIS = ( $GIF_dis -1 ) ( ( $GIF_dis 3 ) $GIF_dis : 3 ) : 2;
$this- COL = ( $GIF_red -1 && $GIF_grn -1 && $GIF_blu -1 )
( $GIF_red | ( $GIF_grn 8 ) | ( $GIF_blu 16 ) ) : -1;
for ( $i = 0; $i count ( $GIF_src ); $i++ ) {
if ( strToLower ( $GIF_mod ) == "url" ) {
$this- BUF [ ] = fread ( fopen ( $GIF_src [ $i ], "rb" ), filesize ( $GIF_src [ $i ] ) );
}
else if ( strToLower ( $GIF_mod ) == "bin" ) {
$this- BUF [ ] = $GIF_src [ $i ];
}
else {
printf ( "%s: %s ( %s )!", $this- VER, $this- ERR [ 'ERR02' ], $GIF_mod );
exit ( 0 );
}
if ( substr ( $this- BUF [ $i ], 0, 6 ) != "GIF87a" && substr ( $this- BUF [ $i ], 0, 6 ) != "GIF89a" ) {
printf ( "%s: %d %s", $this- VER, $i, $this- ERR [ 'ERR01' ] );
exit ( 0 );
}
for ( $j = ( 13 + 3 * ( 2 ( ord ( $this- BUF [ $i ] { 10 } ) & 0x07 ) ) ), $k = TRUE; $k; $j++ ) {
switch ( $this- BUF [ $i ] { $j } ) {
case "!":
if ( ( substr ( $this- BUF [ $i ], ( $j + 3 ), 8 ) ) == "NETSCAPE" ) {
printf ( "%s: %s ( %s source )!", $this- VER, $this- ERR [ 'ERR03' ], ( $i + 1 ) );
exit ( 0 );
}
break;
case ";":
$k = FALSE;
break;
}
}
}
GIFEncoder::GIFAddHeader ( );
for ( $i = 0; $i count ( $this- BUF ); $i++ ) {
GIFEncoder::GIFAddFrames ( $i, $GIF_dly [ $i ] );
}
GIFEncoder::GIFAddFooter ( );
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFAddHeader...
::
*/
function GIFAddHeader ( ) {
$cmap = 0;
if ( ord ( $this- BUF [ 0 ] { 10 } ) & 0x80 ) {
$cmap = 3 * ( 2 ( ord ( $this- BUF [ 0 ] { 10 } ) & 0x07 ) );
$this- GIF .= substr ( $this- BUF [ 0 ], 6, 7 );
$this- GIF .= substr ( $this- BUF [ 0 ], 13, $cmap );
$this- GIF .= "!/377/13NETSCAPE2.0/3/1" . GIFEncoder::GIFWord ( $this- LOP ) . "/0";
}
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFAddFrames...
::
*/
function GIFAddFrames ( $i, $d ) {
$Locals_str = 13 + 3 * ( 2 ( ord ( $this- BUF [ $i ] { 10 } ) & 0x07 ) );
$Locals_end = strlen ( $this- BUF [ $i ] ) - $Locals_str - 1;
$Locals_tmp = substr ( $this- BUF [ $i ], $Locals_str, $Locals_end );
$Global_len = 2 ( ord ( $this- BUF [ 0 ] { 10 } ) & 0x07 );
$Locals_len = 2 ( ord ( $this- BUF [ $i ] { 10 } ) & 0x07 );
$Global_rgb = substr ( $this- BUF [ 0 ], 13,
3 * ( 2 ( ord ( $this- BUF [ 0 ] { 10 } ) & 0x07 ) ) );
$Locals_rgb = substr ( $this- BUF [ $i ], 13,
3 * ( 2 ( ord ( $this- BUF [ $i ] { 10 } ) & 0x07 ) ) );
$Locals_ext = "!/xF9/x04" . chr ( ( $this- DIS 2 ) + 0 ) .
chr ( ( $d 0 ) & 0xFF ) . chr ( ( $d 8 ) & 0xFF ) . "/x0/x0";
if ( $this- COL -1 && ord ( $this- BUF [ $i ] { 10 } ) & 0x80 ) {
for ( $j = 0; $j ( 2 ( ord ( $this- BUF [ $i ] { 10 } ) & 0x07 ) ); $j++ ) {
if (
ord ( $Locals_rgb { 3 * $j + 0 } ) == ( $this- COL 0 ) & 0xFF &
ord ( $Locals_rgb { 3 * $j + 1 } ) == ( $this- COL 8 ) & 0xFF &
ord ( $Locals_rgb { 3 * $j + 2 } ) == ( $this- COL 16 ) & 0xFF
) {
$Locals_ext = "!/xF9/x04" . chr ( ( $this- DIS 2 ) + 1 ) .
chr ( ( $d 0 ) & 0xFF ) . chr ( ( $d 8 ) & 0xFF ) . chr ( $j ) . "/x0";
break;
}
}
}
switch ( $Locals_tmp { 0 } ) {
case "!":
$Locals_img = substr ( $Locals_tmp, 8, 10 );
$Locals_tmp = substr ( $Locals_tmp, 18, strlen ( $Locals_tmp ) - 18 );
break;
case ",":
$Locals_img = substr ( $Locals_tmp, 0, 10 );
$Locals_tmp = substr ( $Locals_tmp, 10, strlen ( $Locals_tmp ) - 10 );
break;
}
if ( ord ( $this- BUF [ $i ] { 10 } ) & 0x80 && $this- IMG -1 ) {
if ( $Global_len == $Locals_len ) {
if ( GIFEncoder::GIFBlockCompare ( $Global_rgb, $Locals_rgb, $Global_len ) ) {
$this- GIF .= ( $Locals_ext . $Locals_img . $Locals_tmp );
}
else {
$byte = ord ( $Locals_img { 9 } );
$byte |= 0x80;
$byte
$byte |= ( ord ( $this- BUF [ 0 ] { 10 } ) & 0x07 );
$Locals_img { 9 } = chr ( $byte );
$this- GIF .= ( $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp );
}
}
else {
$byte = ord ( $Locals_img { 9 } );
$byte |= 0x80;
$byte
$byte |= ( ord ( $this- BUF [ $i ] { 10 } ) & 0x07 );
$Locals_img { 9 } = chr ( $byte );
$this- GIF .= ( $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp );
}
}
else {
$this- GIF .= ( $Locals_ext . $Locals_img . $Locals_tmp );
}
$this- IMG = 1;
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFAddFooter...
::
*/
function GIFAddFooter ( ) {
$this- GIF .= ";";
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFBlockCompare...
::
*/
function GIFBlockCompare ( $GlobalBlock, $LocalBlock, $Len ) {
for ( $i = 0; $i $Len; $i++ ) {
if (
$GlobalBlock { 3 * $i + 0 } != $LocalBlock { 3 * $i + 0 } ||
$GlobalBlock { 3 * $i + 1 } != $LocalBlock { 3 * $i + 1 } ||
$GlobalBlock { 3 * $i + 2 } != $LocalBlock { 3 * $i + 2 }
) {
return ( 0 );
}
}
return ( 1 );
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFWord...
::
*/
function GIFWord ( $int ) {
return ( chr ( $int & 0xFF ) . chr ( ( $int 8 ) & 0xFF ) );
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GetAnimation...
::
*/
function GetAnimation ( ) {
return ( $this- GIF );
}
}


PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永吉县| 梁山县| 二连浩特市| 南京市| 灵山县| 山西省| 高雄县| 陕西省| 东安县| 精河县| 托里县| 浦东新区| 庄浪县| 申扎县| 峨山| 宁化县| 张家港市| 翼城县| 康马县| 张家界市| 无锡市| 萨迦县| 南和县| 福泉市| 大城县| 永年县| 阳东县| 新丰县| 泸定县| 六盘水市| 衡东县| 郸城县| 安陆市| 滁州市| 林甸县| 奎屯市| 探索| 宝丰县| 嵊泗县| 梓潼县| 林周县|