imagetruecolortopalette
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imagetruecolortopalette — 將真彩色影象轉換為調色板影象
說明
   imagetruecolortopalette(resource 
  $image, bool $dither, int $ncolors): boolimagetruecolortopalette() 將一幅真彩色影象轉換為調色板影象。本函式的程式碼原本是從獨立的 JPEG 小組庫程式碼中提取出來的,非常出色。此程式碼被修改以在結果調色板中保留儘可能多的 alpha 通道資訊以及儘可能多的顏色。但並沒有達到期望的效果。通常最好產生真彩色影象輸出,這樣可以保證得到最高的輸出質量。
參數
- 
image
- 
由圖像建立函式(例如imagecreatetruecolor())返回的 GdImage 對象。 
- 
dither
- 
      指明影象是否被抖動(dithered),如果為 true則影象將被抖動使影象中的斑點更多但是顏色更接近。
- 
ncolors
- 
      設定調色板中被保留的顏色的最大數目。 
返回值
   成功時返回 true, 或者在失敗時返回 false。
  
範例
示例 #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);
?>