手记

PHP 绘制各种图形

/*

 * 绘制各种图形

 */

 

//1.创建资源 画布的大小

 $img = imagecreatetruecolor(200, 200);

 $white = imagecolorallocate($img, 0xFF,  0xFF,  0xFF);

 $red = imagecolorallocate($img, 255, 0, 0);

 $blue = imagecolorallocate($img,0, 0, 0xFF);

 $pink = imagecolorallocate($img, 0xFF, 0, 0xFF);

 imagefill($img,0,0,$white);

 //2.制作各种颜色

 imageline($img, 0, 0, 200, 200, $blue);

 imageline($img, 200, 0, 0, 200, $red);

 //3.画出各种图形和写字

 //画矩形

 imagerectangle($img, 50, 50, 150, 150, $pink);

 imagefilledrectangle($img, 75, 75, 125, 125, $blue);

 //画圆

 imageellipse($img, 50, 50, 50, 50, $pink);

 imagefilledellipse($img, 150, 150, 50, 50, $pink);

 //画圆弧

 imagearc($img, 150, 50, 75, 75, 0, 90, $blue);

  

 //画一个字符串

 imagestring($img, 5, 50, 100, 'myweb', $red);

 imagestring($img,6, 10, 10, 'myenglish', $red);

  

 imagettftext($img, 10, 0, 70, 180, $blue, './fonts/simhei.ttf', '津沙港湾');//指定字体

  

 //4.保存 或输出给浏览器 写第二个参数就是保存

 //header("Content-Type:images/png");

 header('Content-type:image/jpeg');

 imagepng($img);

  

 //5.释放资源

 imagedestroy($img);

结果为

0人推荐
随时随地看视频
慕课网APP