<?php include "GIFEncoder.class.php"; /* Build a frames array from sources... */ if ( $dh = opendir ( "frames/" ) ) { while ( false !== ( $dat = readdir ( $dh ) ) ) { if ( $dat != "." && $dat != ".." ) { $frames [ ] = "frames/$dat"; $framed [ ] = 5; } } closedir ( $dh ); } /* GIFEncoder constructor: ======================= image_stream = new GIFEncoder ( URL or Binary data 'Sources' int 'Delay times' int 'Animation loops' int 'Disposal' int 'Transparent red, green, blue colors' int 'Source type' ); */ $gif = new GIFEncoder ( $frames, $framed, 0, 2, 0, 0, 0, "url" ); /* Possibles outputs: ================== Output as GIF for browsers : - Header ( 'Content-type:image/gif' ); Output as GIF for browsers with filename: - Header ( 'Content-disposition:Attachment;filename=myanimation.gif'); Output as file to store into a specified file: - FWrite ( FOpen ( "myanimation.gif", "wb" ), $gif->GetAnimation ( ) ); */ Header ( 'Content-type:image/gif' ); echo $gif->GetAnimation ( ); ?>
实例 2 创建gif动画:
<?php include "GIFEncoder.class.php"; ob_start(); $board_width = 60; $board_height = 60; $pad_width = 5; $pad_height = 15; $ball_size = 5; $game_width = $board_width - $pad_width*2 - $ball_size; $game_height = $board_height-$ball_size; $x = 0; $y = rand(0,$game_height); $xv = rand(1,10); $yv = rand(1,10); $pt[] = array($x,$y); do{ $x += $xv; $y += $yv; if($x > $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); $color2 = 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,$color2); 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(); ?>
以上就是教大家如何利用php合成或是创建gif动画,希望大家仔细研究分享的两个实例,有所收获。
您可能感兴趣的文章: