<?php //第一步 设置文件MIME类型,将输出类型改成图像流。不设置则默认是HTML。header("Content-Type:image/png"); //第二步 创建一个空白的图形区域$im = imagecreatetruecolor(200,200); //第三步 为区域填充背景颜色,第一次对 imagecolorallocate() 的调用会给基于调色板的图像填充背景色$blue = imagecolorallocate($im,0,102,255);imagefill($im,0,0,$blue); //第四步 在背景上绘制$white = imagecolorallocate($im,255,255,255);imageline($im,0,0,200,200,$white);imagestring($im,5,50,50,‘Hello World!‘,$white); //第五步 输出图形imagepng($im); //第六步 输出图像之后,销毁图像,释放内存imagedestroy($im); //第七步 在其他页面调用该图像//<img src="xxx.php" alt="PHP创建的图像"> 在HTML页面调用:
页面显示:
时间: 2025-01-14 04:15:56