日期:2014-05-17  浏览次数:20547 次

php合成或者创建gif动画

1. 首先需要确认GD库是否正常。

?

2. 如何是合成图片,请确保把分解的图片放在frames的文件夹里面。

?

3. 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::GIFAddFrame