一、设定标头,告诉浏览器你要生成的MIME 类型
共三种类型:
- header(‘content-type:image/png’)
- header ( ‘content-type: image/gif’);
- header ( ‘content-type: image/jpeg’ );
<?php header("content-type: image/png");
二、创建一个画布,以后的操作都将基于此画布区域
resource imagecreatetruecolor ( int $width , int $height ) 新建一个真彩色图像
返回一个图像标识符,代表了一幅大小为 width 和 height 的黑色图像。
返回值:成功后返回图象资源,失败后返回 FALSE 。
$width = 200;
$height = 100;
$img = imagecreatetruecolor($width,$height);
三、颜色管理
**int imagecolorallocate ( resource $image , int $red , int $green , int $blue )**为一幅图像分配颜色
red , green 和 blue 分别是所需要的颜色的红,绿,蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xFF
$color = imagecolorallocate($img,0xcc,0xcc,0xcc); // 灰色