(PHP 4 >= 4.0.6, PHP 5)
imagetruecolortopalette — 將真彩色圖像轉換為調色板圖像
說明
bool imagetruecolortopalette ( resource$image
, bool $dither
, int $ncolors
)
imagetruecolortopalette() 將一幅真彩色圖像轉換為調色板圖像。本函數的代碼原本是從獨立的 JPEG 小組庫代碼中提取出來的,非常出色。此代碼被修改以在結果調色板中保留盡可能多的 alpha 通道信息以及盡可能多的顏色。但并沒有達到期望的效果。通常最好生成真彩色圖像輸出,這樣可以保證得到最高的輸出質量。
參數
image
由圖象創建函數(例如imagecreatetruecolor())返回的圖象資源。
dither
指明圖像是否被抖動(dithered),如果為
TRUE
則圖像將被抖動使圖像中的斑點更多但是顏色更接近。
ncolors
設定調色板中被保留的顏色的最大數目。
返回值
成功時返回 TRUE
, 或者在失敗時返回 FALSE
。
范例
Example #1 Converting a true color image to a palette-based image
<?php
// Create a new true color image
$im = imagecreatetruecolor(100, 100);
// Convert to palette-based with no dithering and 255 colors
imagetruecolortopalette($im, false, 255);
// Save the image
imagepng($im, './paletteimage.png');
imagedestroy($im);
?>
注釋
Note: 此函數需要 GD 2.0.1 或更高版本(推薦 2.0.28 及更高版本)。