A leaf image drawing example generated by PHP only

Source: Internet
Author: User
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 );

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.