Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:47:08
Original
1086 people have browsed it

新手对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);
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!