PHP compositing or creating GIF animations
1. First, you need to confirm the GD library is normal.
?
2. How to compose a picture, make sure to place the exploded image in the frames folder.
?
3. GIFEncoder.class.php class
?
?
"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)!", $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 = (3 * (2 << (ord ($this->buf [$i] {ten}) & 0x07)), $k = T RUE; $k; $j + +) {switch ($this->buf [$i] {$j}) {CA Se "!": if ((substr ($this->buf [$i], ($j + 3), 8) = = "Netscap E ") {printf ("%s:%s (%s source)! ", $this->ver, $thi S->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] {ten}) & 0x80) {$cmap = 3 * (2 << (Ord ($this->b UF [0] {ten}) & 0x07)); $this->gif. = substr ($this->buf [0], 6, 7); $this->gif. = substr ($this-&Gt BUF [0], $cmap); $this->gif. = "!\377\13netscape2.0\3\1". Gifencoder::gifword ($this->lop). "The"; }}///:::::::::::::: Gifaddframes;::::---::::--.:::.:;::.::;::: . :: */function Gifaddframes ($i, $d) {$Locals _STR = + 3 * (2 << (Ord $this-&G T BUF [$i] {ten}) & 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] {ten}) & 0x07); $Locals _len = 2 << (ord ($this->buf [$i] {ten}) & 0x07); $Global _rgb = substr ($this->buf [0], 3 * (2 << ( Ord ($this->buf [0] {ten}) & 0x07)); $Locals _rgb = substr ($this->buf [$i], 13, 3 * ( 2 << (Ord ($this->buf [$i] {ten}) & 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] {ten}) & 0x80) {for ($j = 0; $j < (2 << (ord ($this->buf [$i] {ten}) & 0x07); $j + +) {if (Ord ($Locals _rgb {3 * $j + 0}) = = ($this->col >> 0) & 0xFF && Ord ($L OCALS_RGB {3 * $j + 1}) = = ($this->col >> 8) & 0xFF && ORD ($Locals _rgb {3 * $j + 2}) = = ($this->col >>) & 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, strlen ($Locals _tmp)-18); Break Case ",": $Locals _img = substr ($Locals _tmp, 0, 10); $Locals _tmp = substr ($Locals _tmp, ten, StrlEn ($Locals _tmp)-10); Break } if (Ord ($this->buf [$i] {ten}) & 0x80 && $this->img >-1) { if ($Global _len = = $Locals _len) {if (Gifencoder::gifblockcompare ($Global _rgb, $Locals _rgb, $Global _len)) {$this->gif. = ($Locals _ext. $Locals _img. $Loca LS_TMP); } else {$byte = Ord ($Locals _img {9}); $byte |= 0x80; $byte &= 0xF8; $byte |= (Ord ($this->buf [0] {ten}) & 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 &= 0xF8; $byte |= (Ord ($this->buf [$i] {ten}) & 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.::-----getanimation () {return ($this->gif); }}?>
?
4. Example 1 Synthetic GIF animation:
?
?
Getanimation ()); */header (' content-type:image/gif '); echo$gif->getanimation ();? >
?
?
5. Example 2 creates an animated GIF:
?
$game _width) {$xv = -1* $xv; $x = $game _width-($x-$game _width); }elseif ($x < 0) {$XV = -1* $xv; $x = ABS ($x); } if ($y > $game _height) {$yv = -1* $yv; $y = $game _height-($y-$game _height); }elseif ($y <0) {$yv = -1* $yv; $y = ABS ($y); } $pt [] = Array ($x, $y);} while ($x! = $pt [0][0]| | $y! = $pt [0][1]), $i = 0;while (Isset ($pt [$i])) {$image = Imagecreate ($board _width, $board _height); Imagecolorallocate ($image, 0,0,0); $color = Imagecolorallocate ($image, 255,255,255); $color 2 = imagecolorallocate ($image, 255,0,0); if ($pt [$i][1] + $pad _height < $board _width) {imagefilledrectangle ($image, 0, $pt [$i][1], $pad _width, $pt [$i ][1]+ $pad _height, $color); }else{Imagefilledrectangle ($image, 0, $board _width-$pad _height, $pad _width, $board _width, $color); }Imagefilledrectangle ($image, $board _width-$pad _width,0, $board _width, $board _height, $color 2); Imagefilledrectangle ($image, $pad _width+ $pt [$i][0], $ball _size+ $pt [$i][1]-$ball _size, $pad _width+ $pt [$i][0]+ $ball _size, $ball _size+ $pt [$i][1], $color); Imagesetpixel ($image, $pt [$i][0], $pt [$i][1], $color); Imagegif ($image); Imagedestroy ($image); $imagedata [] = Ob_get_contents (); Ob_clean (); + + $i;} $gif = new Gifencoder ($imagedata, 100, 0 , 2, 0, 0, 1, "bin"); Header (' content-type:image/gif '); Echo $gif->getanimation ();? >
?
?
?
?
6. All contents are attached.
?
?
?
?
?