在 Windows Server(IIS + PHP CGI/FastCGI)環境中,`php.ini` 已啟用 `extension=gd`,但 `phpinfo()` 輸出的 **Configure Command** 中未顯示 GD 相關編譯參數,且 `gd_info()` 報錯「未定義函數」。
GD 依賴外部庫:`libpng`、`libjpeg`、`freetype`、`libwebp`、`libxpm`、`libavif` 等。Windows 版 PHP 官方構建已將這些庫**靜態鏈接**進 DLL,**無需額外 DLL**。但若使用第三方構建(如 `php.net` 非官方鏡像),可能需將依賴 DLL 放入 `extension_dir` 或系統 `PATH` 目錄。
**Configure Command 僅反映源碼編譯時的參數**。Windows 官方二進制包是預編譯好的,GD 以共享擴展形式編譯,**不會出現在 Configure Command 中**。判斷 GD 是否啟用的標準是:
<?php
// test_gd.php
if (!extension_loaded('gd')) {
die("GD 擴展未加載\n");
}
$info = gd_info();
echo "GD Version: {$info['GD Version']}\n";
echo "FreeType: " . ($info['FreeType Support'] ? 'Yes' : 'No') . "\n";
echo "JPEG: " . ($info['JPEG Support'] ? 'Yes' : 'No') . "\n";
echo "PNG: " . ($info['PNG Support'] ? 'Yes' : 'No') . "\n";
echo "WebP: " . ($info['WebP Support'] ? 'Yes' : 'No') . "\n";
// 實際繪圖測試
$im = imagecreatetruecolor(200, 100);
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
imagefilledrectangle($im, 0, 0, 199, 99, $white);
imagestring($im, 5, 50, 40, 'GD OK', $red);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
Windows 下 GD 啟用核心在於:**正確的 DLL + 正確的 php.ini + 進程重啟**。Configure Command 無 GD 參數**不代表未啟用**,請以 `gd_info()` 為準。