位置:首页 > PHP > PHP功能函数 > php图片处理函数相关 >

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

字号+ 作者:micloud 来源:www.seoalphas.com 2018-11-05 08:26 浏览量:2536

区别:

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);


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • php图片添加文字水印 以及图片合成加水印图片

    php图片添加文字水印 以及图片合成加水印图片

    浏览次数:5807

  • PHP中data/base64数据流转图片文件输出

    PHP中data/base64数据流转图片文件输出

    浏览次数:5169

  • php获取文章中图片img标签方法

    php获取文章中图片img标签方法

    浏览次数:5018

  • PHP 实现等比压缩图片尺寸和大小实例代码

    PHP 实现等比压缩图片尺寸和大小实例代码

    浏览次数:2846

网友点评
评论区域