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

发表日期:2021-07-01 08:56:02 | 来源: | | 浏览(456) 分类:GD 和图像处理 函数

imagetruecolortopalette

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

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

说明

imagetruecolortopalette(resource $image, bool $dither, int $ncolors): bool

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

参数

image

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

dither

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

ncolors

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

返回值

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

范例

示例 #1 Converting a true color image to a palette-based image

1<?php
2// Create a new true color image$im = imagecreatetruecolor(100, 100);
3// Convert to palette-based with no dithering and 255 colorsimagetruecolortopalette($im, false, 255);
4// Save the imageimagepng($im, './paletteimage.png');
5imagedestroy($im);
6?>

注释

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。