This article mainly introduces a Leaf Image drawing example generated by PHP, hoping to help some friends who use PHP for image programming. Effect:
Tip: save it to the PHP file and paste it in the browser to see the same picture.
The code is as follows:
$ 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, $ ){
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 );
?>