区别:
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);