本文分享兩種基於 GIFEncoder 的滾動字幕實作:水平跑馬燈與垂直逐行滾動,並附上完整類原始碼與關鍵技巧。
hudongbg.gif 作為畫布。imagettftext() 繪製文字,需將編碼轉為 UTF-8。$now = 220 - $count * 5,移出畫面則結束。$imagedata,最後由 GIFEncoder 合成。$gif = new GIFEncoder($imagedata, $diy, 0, 2, 0, 0, 0, "bin");
; 分隔多行文字,轉為陣列處理。$delay 對應每幀顯示時間。$transparent = array(0); $gif = new GIFEncoder($imagedata, $delay, 0, 2, 0, 0, $transparent, "bin");
imagettftext 僅支援 UTF-8,必須 iconv("GB2312","UTF-8",$str)。stripslashes(htmlspecialchars_decode($str)) 反轉義。ziti.ttf 存在且路徑正確。文末提供 V2.06 版完整類別,含標頭/幀/尾部構建、區域/全域調色盤比較、Netscape 循環擴充套件支援等核心邏輯。