图像函数 imagecreatetruecolor()和imagecreate()的异同点

共同点:这两个函数都是用于创建画布

区别:

1.不同的是创建画布和为画布填充颜色的流程不一样;

用imagecreatetruecolor(int x,int y)创建的是一幅大小为 x和 y的图像(默认为黑色),如想改变背景颜色则需要为画布分配颜色imagecolorallcollate(resource:image,red:int,green:int,blue:int),然后为画布填充颜色函数imagefill(resource:image,int x, int y,$color); 

具体代码:

<?php

//设置文件类型为图像
header('Content-Type:image/png');

//创建画布
$image = imagecreatetruecolor(200,200);

//为画布分配颜色
$color = imagecolorallocate($image,174,48,96);

//填充颜色
imagefill($image,0,0,$color);

//生成图像
imagepng($image);

//保存图像,生成图像和保存图像需要分为两步,要么只能生成,要么只能保存
imagepng($image,'./1.png');
?>

用imagecreate(int x,int y)创建的也是一幅大小为 x和 y的图像(默认没有颜色,需要指定颜色),如想改变背景颜色则需要为画布分配颜色imagecolorallcollate(resource:image,red: int,green:int ,blue:int),和上面不同的是不需要填充,因为imagecolorallcollate()在imagecreate()函数创建画布的情况下自动填充.

具体代码:

<?php
//设置文件类型为图像
header('Content-Type:image/png');

//创建画布
$image = imagecreate(200,200);

//为画布分配颜色并填充画布
$color = imagecolorallocate($image,174,48,96);

//生成图像
imagepng($image);

//保存图像,生成图像和保存图像需要分为两步,要么只能生成,要么只能保存
imgaepng($image,'./1.png');
?>

2.支持的颜色数不同,imagecreatetruecolor()支持的颜色更多一些.

 

转载于:https://www.cnblogs.com/fantianlong/p/9898579.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值