课时250 PHP中GD库的使用
课时251 使用GD库画图
<?php
//1.创建资源(画布的大小)
$img = imagecreatetruecolor(200,200);
//设置画布的颜色
$white = imagecolorallocate($img,0xFF,0xFF,0xFF);
$red = imagecolorallocate($img,255,0,0);
$blue = imagecolorallocate($img,0,0,255);
imagefill($img,0,0,$red);
//2.制作各种颜色
imageline($img,0,0,200,200,$blue); //前两个是起始的XY坐标,后两个是结束的XY坐标
//3.画出各种图形,写字
//4.保存,输出给浏览器
header("Content-Type:images/png");
imagepng($img,"./test.png");
//5.关闭资源
imagedestroy($img);
?>
<img src="./test.png">图片</img>
结果:
图片
课时252 绘制各种图形
<?php
//1.创建资源(画布的大小)
$img = imagecreatetruecolor(200,200);
//设置画布的颜色
$white = imagecolorallocate($img,0xFF,0xFF,0xFF);
$red = imagecolorallocate($img,255,0,0);
$blue = imagecolorallocate($img,0,0,255);
$green = imagecolorallocate($img,0,255,0);
imagefill($img,0,0,$red);
//2.制作各种颜色
imageline($img,0,0,200,200,$blue); //前两个是起始的XY坐标,后两个是结束的XY坐标
//3.画出各种图形,写字
//画矩形
imagerectangle($img,50,50,150,150,$white);
imagefilledrectangle($img,75,75,125,125,$green);
//画圆形
imageellipse($img,50,50,100,100,$blue);
imagefilledellipse($img,150,150,100,100,$blue);
//画弧形
imagearc($img,150,50,100,100,-90,90,$green);
//写字
imagestring($img,5,50,150,"hello",$white);
imagestringup($img,5,30,150,"hello",$white);
//4.保存,输出给浏览器
//header("Content-Type:images/png");
imagepng($img,"./test.png");
//5.关闭资源
imagedestroy($img);
?>
<img src="./test.png">图片</img>
课时253 画时钟