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

imagepalettetotruecolor

(PHP 5 >= 5.5.0, PHP 7)

imagepalettetotruecolor - 将基于调色板的图像转换为真彩色

描述

代码语言:javascript
复制
bool imagepalettetotruecolor ( resource $src )

将由像imagecreate()这样的函数创建的基于调色板的图像转换为真彩色图像,如imagecreatetruecolor()。

参数

代码语言:txt
复制
`image`   

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

返回值

返回TRUE如果皈依完成,或者如果源图像已经是一个真正的彩色图像,否则返回FALSE

例子

Example #1 Converts any image resource to true color

代码语言:javascript
复制
<?php
//?Backwards?compatiblity
if(!function_exists('imagepalettetotruecolor'))
{
????function?imagepalettetotruecolor(&$src)
????{
????????if(imageistruecolor($src))
????????{
????????????return(true);
????????}

????????$dst?=?imagecreatetruecolor(imagesx($src),?imagesy($src));

????????imagecopy($dst,?$src,?0,?0,?0,?0,?imagesx($src),?imagesy($src));
????????imagedestroy($src);

????????$src?=?$dst;

????????return(true);
????}
}

//?Helper?closure
$typeof?=?function()?use($im)
{
????echo?'typeof($im)?=?'?.?(imageistruecolor($im)???'true?color'?:?'palette'),?PHP_EOL;
};

//?Create?a?palette?based?image
$im?=?imagecreate(100,?100);
$typeof();

//?Convert?it?to?true?color
imagepalettetotruecolor($im);
$typeof();

//?Free?the?memory
imagedestroy($im);
?>

上面的例子将输出:

代码语言:javascript
复制
typeof($im) = palette
typeof($im) = true color

← imagepalettecopy

imagepng →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com