在php中如何输出动态gif
内容导读
收集整理的这篇技术教程文章主要介绍了在php中如何输出动态gif,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含8727字,纯文字阅读大概需要13分钟。
内容图文
首先需要确认GD库是否正常,如果是合成图片,请确保把分解的图片放在frames的文件夹里面。
相关推荐:《PHP入门教程》
GIFEncoder.class.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 .= "!37713NETSCAPE2.031" . GIFEncoder::GIFWord ( $this->LOP ) . "