三、创建图像步骤
在PHP中创建一个图像通常需要以下四个步骤:
1. 创建一个背景图像,以后所以操作但是基于此背景。
2. 在图像上绘图轮廓或或者输入文本。
3. 输出最终图形。
4. 清除内存中所有资源。
下面我们看一个应用实例,一个带“PHP”标签的正方型。脚本如下:
|
<?php $height = 300; $width = 300; $im = ImageCreateTrueColor($width, $height); $white = ImageColorAllocate ($im, 255, 255, 255); $blue = ImageColorAllocate ($im, 0, 0, 64); ImageFill($im, 0, 0, $blue); ImageLine($im, 0, 0, $width, $height, $white); ImageString($im, 4, 80, 150, 'PHP', $white); Header ('Content-type: image/png'); ImagePng ($im); ImageDestroy($im); ?> |
最后把这一小段脚本保存为si1.php,然后用浏览器对它进行访问,就可以看到一个300×300像素大小的PNG格式的图像,见图3。

图3 PNG图像格式输出到浏览器的界面
上一页 [1] [2] [3] [4] [5] [6] 下一页