首页 > php图像处理 > php 创建图像实例

php 创建图像实例

使用ImageCreate()创建一个代表空白图像的变量,这个函数要求以像素为单位的图像大小的参数,其格式是ImageCreate(x_size, y_size),如果要创建一个大小为250×250的图像,就可以使用下面的语句:

<? header ("content-type: image/png");$newimg = imagecreate(250,250);?>

由于图像还是空白的,因此你可能会希望用一些彩色来填充它,你需要首先使用imagecolorallocate()函数用其rgb值为这种颜色指定一个名字,这一函数的格式为imagecolorallocate([image],[red],[green],[blue]),如果要定义天蓝色,可以使用如下的语句:

$skyblue = imagecolorallocate($newimg,136,193,255);   

接下来,需要使用imagefill()函数用这种颜色填充这个图像,imagefill()函数有几个版本,例如imagefillrectangle()、imagefillpolygon()等,为简单起见,我们通过如下的格式使用imagefill()函数,代码如下:

imagefill([image], [start x point], [start y point], [color])

imagefill($newimg,0,0,$skyblue);  

最后,在图像建立后释放图像句柄和所占用的内存,代码如下:

imagepng($newimg);imagedestroy($newimg);

这样,创建图像的全部代码如下所示:

header ("content-type: image/png"); 
$newimg = imagecreate(250,250); 
$skyblue = imagecolorallocate($newimg,136,193,255); 
imagefill($newimg,0,0,$skyblue); 
imagepng($newimg); 
imagedestroy($newimg);


本文地址:http://www.phprm.com/tuxiang/fs4461.html

转载随意,但请附上文章地址:-)

标签:php 创建图像实例

相关文章

发表留言