Ming 是一個 C 撰寫的函式庫,提供 PHP 擴展,可在伺服器端動態建立 SWF (Flash) 動畫,無需 Macromedia Flash 製作工具。適用於根據資料庫內容產生圖表、廣告條、互動式簡報等場景。
./configure --with-ming 或安裝套件 php-ming (Debian/Ubuntu)。php -m | grep ming 或 phpinfo() 檢查。同 Flash IDE:先建立 符號(圖形、影片剪輯、按鈕),再將符號放入場景成為 實例,定義每幀行為,最後輸出 SWF。
SWFMovie、SWFShape、SWFSprite (MovieClip)、SWFButton、SWFFont、SWFText、SWFAction 等。new SWFMovie() → 設定尺寸、背景、幀率 → add() 放入形狀/文字/按鈕 → output() 輸出至瀏覽器或 save() 存檔。<?php
header("Content-Type: application/x-shockwave-flash");
$movie = new SWFMovie();
$movie->setDimension(400, 300);
$movie->setBackground(0xFF, 0xFF, 0xFF);
$movie->setRate(12); // 12 fps
// 建立紅色矩形形狀
$shape = new SWFShape();
$shape->setRightFill($shape->addFill(0xFF, 0, 0));
$shape->movePenTo(50, 50);
$shape->drawLineTo(350, 50);
$shape->drawLineTo(350, 250);
$shape->drawLineTo(50, 250);
$shape->drawLineTo(50, 50);
// 將形狀加入影片,取得實例
$instance = $movie->add($shape);
$instance->moveTo(200, 150); // 置中
// 加入文字
$font = new SWFFont("path/to/font.fdb"); // 需預先轉換字型
$text = new SWFText();
$text->setFont($font);
$text->setColor(0, 0, 0);
$text->setHeight(24);
$text->addString("Hello Ming!");
$textInstance = $movie->add($text);
$textInstance->moveTo(180, 140);
// 輸出 SWF 到瀏覽器
$movie->output();
?>
SWFButton 與 SWFAction 送出 GET/POST。注意:Flash Player 已於 2020/12/31 終止支援,主流瀏覽器已移除外掛。Ming 庫長期未更新(最後版本 0.4.8,2016 年),不建議用於新專案。現代替代方案:
Chart.js、D3.js、ECharts 繪製互動圖表。本文僅作技術歷史參考,展示 PHP 伺服器端向量圖形產生的思想。