纯PHP生成的一个树叶图片画图例子
效果:
提示:保存到php文件然后在浏览器中打后即可看到和效果图一样的一张图片。
<?php
$im=imagecreate(670,500);
$white = imagecolorallocate($im, 0xff, 0xff, 0xff);
$g = imagecolorallocate($im, 0x00, 0x00, 0x00);
define("pii",m_pi/180);
function drawleaf($g,$x,$y,$l,$a){
global $im;
$b = 50;
$c =9;
$s1 = 2;
$s2 = 3 ;
$s3 = 1.2;
if($l > $s1)
{
$x2 = $x + $l * cos($a * pii);
$y2 = $y + $l * sin($a * pii);
$x2r = $x2 + $l / $s2 * cos(($a + $b) * pii);
$y2r = $y2 + $l / $s2 * sin(($a + $b) * pii);
$x2l = $x2 +$l / $s2 * cos(($a - $b) * pii);
$y2l = $y2 + $l / $s2 * sin(($a - $b) * pii);
$x1 = $x + $l / $s2 * cos($a * pii);
$y1 = $y + $l / $s2 * sin($a * pii);
$x1l = $x1 + $l / $s2 * cos(($a - $b) * pii);
$y1l = $y1 + $l / $s2 * sin(($a - $b) * pii);
$x1r = $x1 + $l / $s2 * cos(($a + $b) * pii);
$y1r = $y1 + $l / $s2 * sin(($a + $b) * pii);
imageline($im,(int)$x, (int)$y, (int)$x2, (int)$y2, $g);
imageline($im,(int)$x2, (int)$y2, (int)$x2r, (int)$y2r, $g);
imageline($im,(int)$x2, (int)$y2, (int)$x2l, (int)$y2l, $g);
imageline($im,(int)$x1, (int)$y1, (int)$x1l, (int)$y1l, $g);
imageline($im,(int)$x1, (int)$y1, (int)$x1r, (int)$y1r, $g);
drawleaf($g, $x2, $y2, $l / $s3, $a + $c);
drawleaf($g, $x2r, $y2r, $l / $s2, $a + $b);
drawleaf($g, $x2l, $y2l, $l / $s2, $a - $b);
drawleaf($g, $x1l, $y1l, $l / $s2, $a - $b);
drawleaf($g, $x1r, $y1r, $l / $s2, $a + $b);
}
}
drawleaf($g,300,500,100,270);
header("content-type: image/png");
imagepng($im);
?>
下一篇: 网站权重优化需要注意几点