Php method for drawing a positive cosine curve on an image

Source: Internet
Author: User
Php method for drawing a positive cosine curve on an image

  1. /**
  2. * Method for drawing a positive cosine curve on an image
  3. * Edit: bbs.it-home.org
  4. */
  5. Define ("MAX_WIDTH_PIXEL", 600 );
  6. Define ("MAX_HEIGHT_PIXEL", 240 );
  7. // Send the header information
  8. Header ("Content-type: image/gif ");
  9. // Create an image
  10. $ Img = imageCreate (MAX_WIDTH_PIXEL, MAX_HEIGHT_PIXEL );
  11. // Set the color
  12. $ Bgcolor = imageColorAllocate ($ img, 0xff, 0xe9, 0xe9 );
  13. $ Red = imageColorAllocate ($ img, 255, 0, 0 );
  14. $ Blue = imageColorAllocate ($ img, 0, 0,255 );
  15. $ Brown = imageColorAllocate ($ img, 100, 0, 0 );
  16. $ Black = imageColorAllocate ($ img, 0, 0, 0 );
  17. $ Width = MAX_WIDTH_PIXEL/2; // width
  18. $ Height = MAX_HEIGHT_PIXEL/2; // height
  19. // Create an axis
  20. ImageLine ($ img, $ width, 0, $ width, MAX_HEIGHT_PIXEL, $ black); // Y axis
  21. ImageLine ($ img, 0, $ height, MAX_WIDTH_PIXEL, $ height, $ black); // x axis
  22. // Use loops to depict function images
  23. For ($ I = 0; $ I <= MAX_WIDTH_PIXEL; $ I ++)
  24. {
  25. $ Y1 = 100 * sin ($ I/100 * M_PI );
  26. ImageSetPixel ($ img, $ I, $ height + $ y1, $ blue );
  27. $ Y2 = 100 * sin ($ I/300 * M_PI );
  28. ImageSetPixel ($ img, $ I, $ height + $ y2, $ red );
  29. $ Y3 = 100 * sin ($ I/300 * M_PI );
  30. ImageSetPixel ($ img, $ I, $ height-$ y3, $ brown );
  31. }
  32. // Display the image
  33. ImageGif ($ img );
  34. // Release resources
  35. ImageDestroy ($ img );
  36. ?>

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.