最族
php图像生成函数imagecreatetruecolor()和imagecreate()的区别
2015-9-8 Veris
新手对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案例如下: 

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

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


发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容