欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

php图像生成函数之间的区别分析_基础知识

程序员文章站 2022-03-20 22:45:30
...
新手对php图像生成函数imagecreatetruecolor()和imagecreate()又不解之处,首先来看看官方对这两个函数的解释:
resource imagecreatetruecolor ( int $x_size , int $y_size )
返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像。
resource imagecreate ( int $x_size , int $y_size )
返回一个图像标识符,代表了一幅大小为
两者在改变背景颜色时有些区别
imagecreatetruecolor需要用imagefill()来填充颜色
imagecreate()需要用imagecolorAllocate()添加背景色
php案例如下
复制代码 代码如下:

$img = imagecreatetruecolor(100,100); //创建真彩图像资源
$color = imagecolorAllocate($img,200,200,200); //分配一个灰色
imagefill($img,0,0,$color); // 从左上角开始填充灰色
header('content-type:image/jpeg'); //jpg格式
imagejpeg($img); //显示灰色的方块
?>

复制代码 代码如下:

$img = imagecreate(100,100);
imagecolorallocate($img,200,200,200);
header('content-type:image/jpeg');
imagejpeg($img);
?>