导航首页 » 技术教程 » PHP:imagetruecolortopalette()的用法_GD库图像处理函数
PHP:imagetruecolortopalette()的用法_GD库图像处理函数 174 2023-12-15   

imagetruecolortopalette

(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 及更高版本)。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103