Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

PHP如何更改imagecreatetruecolor函数背景色?

后来将imagecreatetruecolor函数换成了imagecreate()函数使用后,再给图像分配颜色就能正常更改颜色了,但是这并不是在使用imagecreatetruecolor函数的情况下,昨日无意中发现了更改imagecreatetruecolor函数背景色的方法。

php如何更改imagecreatetruecolor函数背景色?在前面写的《PHP使用imagecreatetruecolor函数颜色一直为黑色怎么办?PHP创建真彩色图像为黑色怎么办?》一文中,当时在实例代码中使用imagecreatetruecolor函数创建了一张图片,一直修改不了这张新建图片的黑色背景色。

PHP如何更改imagecreatetruecolor函数背景色?插图
PHP如何更改imagecreatetruecolor函数背景色?插图

PHP使用imagecreatetruecolor函数颜色一直为黑色怎么办?

后来将imagecreatetruecolor函数换成了imagecreate()函数使用后,再给图像分配颜色就能正常更改颜色了,但是这并不是在使用imagecreatetruecolor函数的情况下,昨日无意中发现了更改imagecreatetruecolor函数背景色的方法。

PHP如何更改imagecreatetruecolor函数背景色?插图2
PHP如何更改imagecreatetruecolor函数背景色?

我们如果使用imagecreatetruecolor函数之后再使用imagecolorallocate()函数,是无法直接对imagecreatetruecolor函数新建的图像进行处理的,这个时候我们需要使用imagefill()函数再做进一步处理即可改变imagecolorallocate()函数生成的图像黑色背景。

imagefill()函数用法

imagefill()函数语法格式

imagefill(
    resource $image,
    int $x,
    int $y,
    int $color
): bool

imagefill()函数作用

对图像的区域颜色进行填充。

imagefill()函数参数说明

imagefill()在image图像的坐标x,y(图像左上角为 0, 0)处用color颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。

更改imagecreatetruecolor函数新建图像的背景色实例

<?php
header('Content-type: image/png');
//创建一个宽高为200像素的真彩色图像
$pic = imagecreatetruecolor(200, 200);
// 将背景设为白色
$white = imagecolorallocate($pic, 255, 255, 255);
//从图像的X、Y轴坐标为0的位置开始填充白色背景
imagefill($pic, 0, 0, $white);
//保存图像
imagepng($pic);
//输出图像
echo "<img src=\"$pic\">";
//销毁图像是否内存
imagedestroy($pic);
?> 

在《PHP使用imagecreatetruecolor函数颜色一直为黑色怎么办?PHP创建真彩色图像为黑色怎么办?》一文,虽然最终也实现了自己想要的图像背景颜色,但是在PHP手册中关于imagecreate()函数的说明中建议我们在PHP中使用imagecreatetruecolor()函数来新建图像。

温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

html字体怎么添加颜色?Html字体颜色如何设置实例

2016-5-31 9:00:00

编程技巧

Windows服务器和Linux服务器有什么不同?

2016-6-3 9:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索