• 微信

PHP GD2知识点:imagecreatetruecolor()和imagecreate()的区别

作者:Alpha时间:2018-11-05 阅读数:3230 +人阅读

区别:

imagecreatetruecolor():新建一个真彩色图像资源(默认黑色),如想改变背景颜色则需要用填充颜色函数imagefill($img,0,0,$color);合成图片不会有颜色损失,保证图片质量度。

imagecreate():新建一个空白图像资源,用imagecolorAllocate()添加背景色;合成图片时会有颜色损失,图片变的模糊。

imagecreatetruecolor示例代码如下:

header("Content-type:text/html;charset=utf-8");             //设置页面编码风格
header("Content-type:image/jpg");                    //告知浏览器输出的是图片

$image = imagecreatetruecolor(300,150);                //创建真彩图像资源
$bgcolor = imagecolorallocate($image,200,200,200);          //分配一个灰色
imagefill($image,0,0,$bgcolor);                     // 从左上角开始填充灰色
imagejpeg($image);

imagedestroy($image);                         //销毁画布资源

imagecreate()示例代码如下:

header("Content-type:text/html;charset=utf-8");             //设置页面编码风格
header("Content-type:image/jpg");                    //告知浏览器输出的是图片
$image = imagecreate(400,300);                    //设置画布大小
$bgcolor = imagecolorallocate($image,255,60,60);           //设置画布的背景颜色
imagejpeg($image);                           //输出图像
imagedestroy($image);


本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com

阿尔法

软件开发工程师#全栈工程师

{include file=foot.html}