A Sample GD::Graph Application
As an example of using GD::Graph, we’ll implement a web-based biorhythm server. The general idea of biorhythms is that cyclic processes in nature (seasonal changes, and particularly the changing phases of the moon) are reflected in the processes of the human body. Although they have no real basis in scientific study, these cyclic patterns have captured people’s imaginations for years. You can even get your biorhythm read by coin-operated machines at many rest stops on America’s highways.
Here’s how the biorhythm server works. First, a user enters her birth date, and a range of dates for the biorhythm report. These are submitted via a CGI script to a Perl script that creates a graph for the three primary biorhythm patterns: physical, emotional, and intellectual. These three patterns unfold as sine waves starting from the date of birth, with periods of 23 days for the physical cycle, 28 days for the emotional cycle, and 33 days for the intellectual cycle. The biorhythmic cycles are defined based upon these numbers.
The biopage.cgi script (Example 4-1) builds the HTML page, including the form used to enter the data for the script. It then passes the data to the biorhythm.cgi script (Example 4-2), which uses the GD::Graph module to create a biorhythm chart from the data and sends it to the browser as a PNG image data stream. The biopage.cgi script is accessed for the first time without any data fields with the URL http://www.yoururl.com/cgi-bin/biopage.cgi ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access