彰化一整天的論壇

 找回密碼
 立即註冊
查看: 390|回復: 0

Howto: Generate animated GIF with PHP

[複製鏈接]
發表於 2018-5-21 16:50:02 | 顯示全部樓層 |閱讀模式


  1. header ('Content-type:image/gif');
  2. include('GIFEncoder.class.php');
  3. $text = "Hello World";

  4. // Open the first source image and add the text.
  5. $image = imagecreatefrompng('source01.png');
  6. $text_color = imagecolorallocate($image, 200, 200, 200);
  7. imagestring($image, 5, 5, 5,  $text, $text_color);

  8. // Generate GIF from the $image
  9. // We want to put the binary GIF data into an array to be used later,
  10. //  so we use the output buffer.
  11. ob_start();
  12. imagegif($image);
  13. $frames[]=ob_get_contents();
  14. $framed[]=40;

  15. // Delay in the animation.
  16. ob_end_clean();

  17. // And again..
  18. // Open the first source image and add the text.
  19. $image = imagecreatefrompng('source02.png');
  20. $text_color = imagecolorallocate($image, 200, 200, 200);
  21. imagestring($image, 5, 20, 20,  $text, $text_color);

  22. // Generate GIF from the $image
  23. // We want to put the binary GIF data into an array to be used later,
  24. //  so we use the output buffer.
  25. ob_start();
  26. imagegif($image);
  27. $frames[]=ob_get_contents();
  28. $framed[]=40;

  29. // Delay in the animation.
  30. ob_end_clean();

  31. // Generate the animated gif and output to screen.
  32. $gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');
  33. echo $gif->GetAnimation();
複製代碼
資料來源: https://www.jeroenvanwissen.nl/w ... imated-gif-with-php
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  

GMT+8, 2019-12-12 22:00 , Processed in 0.173926 second(s), 32 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表