imagetruecolortopalette

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

imagetruecolortopalette将真彩色图像转换为调色板图像

说明

imagetruecolortopalette(GdImage $image, bool $dither, int $num_colors): bool

imagetruecolortopalette()将一幅真彩色图像转换为调色板图像。本函数的代码原本是从独立的 JPEG 小组库代码中提取出来的,非常出色。此代码被修改以在结果调色板中保留尽可能多的 alpha 通道信息以及尽可能多的颜色。但并没有达到期望的效果。通常最好生成真彩色图像输出,这样可以保证得到最高的输出质量。

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

dither

指明图像是否被抖动(dithered),如果为 true 则图像将被抖动使图像中的斑点更多但是颜色更接近。

num_colors

设定调色板中被保留的颜色的最大数目。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 image 现在需要 GdImage 实例;之前需要有效的 gd resource

范例

示例 #1 将真彩色图像转换为基于调色板的图像

<?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);
?>

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top