首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

imagetruecolortopalette

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

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

描述

代码语言:javascript
复制
bool imagetruecolortopalette ( resource $image , bool $dither , int $ncolors )

imagetruecolortopalette()将真彩图像转换为调色板图像。此功能的代码最初是从Independent JPEG Group库代码中提取的,非常出色。代码已被修改,以便在最终的调色板中保留尽可能多的alpha通道信息,并尽可能保留颜色。这可能不如希望的那样好。通常最好是简单地生成一个真彩色输出图像,以保证最高的输出质量。

参数

代码语言:txt
复制
`image`   

一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。

dither

指示图像是否应抖动 - 如果是TRUE,则将使用抖动,这将导致更多的斑点图像,但具有更好的颜色逼近。

ncolors

设置应该保留在调色板中的最大颜色数量。

返回值

成功返回TRUE或失败时返回FALSE。

例子

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

代码语言:javascript
复制
<?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);
?>

← imagesy

imagettfbbox →

扫码关注腾讯云开发者

领取腾讯云代金券