Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


which specifies the font to be used (Palatino-Italic) and the size in points (36). It’s important that you set up boundaries large enough to hold your font in the size you’ve chosen, otherwise the characters or graphics will run off the edge of the box.


TIP:  Points are used in typesetting measurements in the United States. There are about 72 points per inch—72.27, to be precise. Therefore, a 36-point character will be about a half-inch high. You’ll need to experiment with your computer to get a rough idea of how many pixels per inch your monitor can display. It depends on your display resolution and the size of your monitor. A good place to start is 70 to 80 pixels per inch. Try some different bounding boxes and measure them with a ruler to be sure.

The next two lines of PostScript code define the colors to be used in the graphic:

   /white    {1 1 1 setrgbcolor} def
   /black    {0 0 0 setrgbcolor} def

These are “RGB” definitions, which means the first number in the three-digit sequence stands for red, the second for green, and the third for blue. Turning all of them on gives white; the reverse gives black.

The statement black clippath fill fills the entire drawing region—the bounding box—with black; 10 10 moveto starts the image 10 pixels up and 10 to the right, which will center our image nicely. Finally, we tell Ghostscript to draw the value in $count in white with ($count) white show.

Every PostScript program must end with showpage if you want anything to be displayed.

This program creates an image file in JPEG format that can then be called up in the Web page to display the access count. Every time it’s run, Ghostscript simply overwrites the existing counter.jpg file, ensuring that an updated count is stored there graphically every time.

It’s simple.


EXERCISE:  The Sambar Server: Building Your Web Site

SSI introduces many possibilities for your Sambar Web site. Use your imagination to come up with more uses for dynamically generated graphics using Ghostscript. Here are a few ideas:

  Experiment on your home page with some of the SSI directives, especially #include and #exec. See what happens when you run a program from the server.
  Add a graphical access counter to your home page using what you’ve learned so far.
  The Sambar server package includes its own access counter with graphics, written in the C programming language. The source code comes with the package; study it to see if you can figure out what the program does. With your Perl experience, even if you’ve never seen a line of C, you’ll be surprised at how much you recognize.

Moving On

You’ve learned about some non-CGI methods of creating dynamic Web pages through the server-side includes. You’ve also learned how to generate graphical images on the fly with Ghostscript and Perl.

In the next skill, we’ll cover some methods of monitoring activity on your Web site, using Perl scripts to parse the information in your log files and generate graphical reports that can be viewed with a Web browser.

Are You Experienced?

Now you can…

  use the additional power SSI gives to static HTML documents
  understand how SSI works through the Web server
  see how PostScript files are structured
  generate your own dynamic graphical images with Ghostscript


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.