PHP compositing or creating GIF animations

Source: Internet
Author: User
1. First, you need to confirm the GD library is normal.

2. If you are composing a picture, be sure to place the exploded image in the frames folder.

3. GIFEncoder.class.php class
  1. Include "GIFEncoder.class.php";
  2. Ob_start ();
  3. $board _width = 60;
  4. $board _height = 60;
  5. $pad _width = 5;
  6. $pad _height = 15;
  7. $ball _size = 5;
  8. $game _width = $board _width-$pad _width*2-$ball _size;
  9. $game _height = $board _height-$ball _size;
  10. $x = 0;
  11. $y = rand (0, $game _height);
  12. $XV = rand (1,10);
  13. $YV = rand (1,10);
  14. $pt [] = Array ($x, $y);
  15. do{
  16. $x + = $XV;
  17. $y + = $yv;
  18. if ($x > $game _width) {
  19. $XV = -1* $XV;
  20. $x = $game _width-($x-$game _width);
  21. }elseif ($x < 0) {
  22. $XV = -1* $XV;
  23. $x = ABS ($x);
  24. }
  25. if ($y > $game _height) {
  26. $yv = -1* $yv;
  27. $y = $game _height-($y-$game _height);
  28. }elseif ($y <0) {
  29. $yv = -1* $yv;
  30. $y = ABS ($y);
  31. }
  32. $pt [] = Array ($x, $y);
  33. }while ($x! = $pt [0][0]| | $y! = $pt [0][1]);
  34. $i = 0;
  35. while (Isset ($pt [$i])) {
  36. $image = Imagecreate ($board _width, $board _height);
  37. Imagecolorallocate ($image, 0,0,0);
  38. $color = Imagecolorallocate ($image, 255,255,255);
  39. $color 2 = imagecolorallocate ($image, 255,0,0);
  40. if ($pt [$i][1] + $pad _height < $board _width) {
  41. Imagefilledrectangle ($image, 0, $pt [$i][1], $pad _width, $pt [$i][1]+ $pad _height, $color);
  42. }else{
  43. Imagefilledrectangle ($image, 0, $board _width-$pad _height, $pad _width, $board _width, $color);
  44. }
  45. Imagefilledrectangle ($image, $board _width-$pad _width,0, $board _width, $board _height, $color 2);
  46. 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);
  47. Imagesetpixel ($image, $pt [$i][0], $pt [$i][1], $color);
  48. Imagegif ($image);
  49. Imagedestroy ($image);
  50. $imagedata [] = Ob_get_contents ();
  51. Ob_clean ();
  52. + + $i;
  53. }
  54. $gif = new Gifencoder (
  55. $imagedata,
  56. 100,
  57. 0,
  58. 2,
  59. 0, 0, 1,
  60. "Bin"
  61. );
  62. Header (' content-type:image/gif ');
  63. echo $gif->getanimation ();
  64. ?>
Copy Code
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.