Copyright ©1996, Que Corporation. All rights reserved. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Que Corporation, 201 West 103rd Street, Indianapolis, IN 46290 or at support@mcp.com.

Notice: This material is excerpted from Running A Perfect Web Site with Apache, ISBN: 0-7897-0745-4. The electronic version of this material has not been through the final proof reading stage that the book goes through before being published in printed form. Some errors may exist here that are corrected before the book is published. This material is provided "as is" without any warranty of any kind.

Chapter 11 - Graphics and Imagemaps

As with the earlier chapter on htmL authoring tools, this chapter will briefly mention the UNIX graphics tools available, but will mostly talk about the Windows tools, since we anticipate that's what the majority of you folks will be using, even if the site is hosted on a UNIX platform.

One of the strongest draws to the World Wide Web is graphics. In 1993 with the 2.0 release of NCSA Mosaic, inline graphics became part of Web pages and made them much more interesting than plain-text documents. Now, just a handful of years later, it's possible to animate the graphics on a Web page by using server push techniques (for the Netscape Navigator) or by using Java, the newest trend in Web programming languages. While these applications are compelling, they are, unfortunately, outside the scope of an introductory chapter on graphics.

Web graphics basically come in two flavors: gif (for Graphics Interchange Format), a format developed by CompuServe, and JPEG (for Joint Picture Experts Group). Each format has its merits and drawbacks. You'll want to choose one or the other based on how you're using images on your pages. If you have designers at your disposal to produce your graphics, all you need to do is take the hand-off from them and put the files where they belong on your server. Otherwise, you'll need to develop some expertise in a graphics program so you can create your own.

In Chapter 9, you learned how to use the <IMG ...> tag to place an inline image in your documents. You later saw that sandwiching an <IMG ...> tag between the <A ...> and </A> tags set up a linked graphic, or hypergraphic, that users can click on to jump to another document. An extension of this idea is the imagemap. Imagemaps are graphics that have been divided into special sections called hot regions. Clicking on different hot regions instructs the browser to load different URLs. You've probably seen imagemaps on the main pages of many Web sites, where they provide a popular point-and-click interface to the rest of the site. The first implementation of imagemaps placed the burden of figuring out which URL to load squarely on the server (server-side imagemaps), but the current trend is to shift this burden to the client (client-side imagemaps).

In this chapter, you learn about:

  • The basics of the gif and JPEG graphics formats

  • Several different graphics programs and what features they have to assist with the development of Web page graphics

  • Server-side and client-side imagemaps

  • Tools to help you create and test imagemaps

Graphics Standards

There are a large number of graphics storage formats in the world, but only two are used in the Web graphics realm: gif and JPEG. gif is the format originally put forward in htmL standards, but more and more browsers are able to display JPEG images as well.


It is often possible to configure a browser to use a helper application to display images stored in formats other than gif or JPEG. For example, you can instruct the browser to run a TIFF format viewer if it encounters an image file that has a .tif extension.

The next few sections look at some of the specifics of the gif and JPEG formats.

gif

The gif format was originally developed by CompuServe as a standard for storing and transmitting images. gif is an 8-bit format, meaning that gif images are limited to 256 colors. The current gif specification, released by CompuServe in 1990, is gif89a.

How gif Works

Image data in gif format is organized into related blocks and sub-blocks that can be used to reproduce the graphic. When transmitting a gif, a program called an encoder is used to produce a gif data stream of control and data blocks that are sent along to the destination machine. There, a program called a decoder parses the data stream and assembles the image.

gif employs a compression scheme called LZW compression to reduce the amount of data it needs to send to completely describe the image. LZW compression works best on simple images like line drawings or graphics with a only a few distinct colors. For more color-rich images, LZW is less efficient, producing compression ratios around 2:1 or less.

Interlaced gifs

When you place an inline gif on a Web page, the browser reads it in over the course of one pass over the area the image is to occupy. During the pass, each pixel is set to exactly what it has to be to produce the image. The problem with this approach is that it can take a while for the entire image to be read in. One way to reduce this time and still give the user an idea of what the whole image looks like is to use interlaced gifs.

An interlaced gif file contains the same image data as a regular gif file, but it is organized differently. As a browser decodes an interlaced gif, it receives incomplete information about the entire image. As it presents this information on-screen, an incomplete version of the whole image shows up. Because it is incomplete, the quality of the image will not be very good, but it is usually good enough to impart a sense of what the final image will look like. As it continues to read more data, the approximation to the actual image is improved, producing a "fade in" effect. When the browser reaches the end of the file, it has all of the image data and it makes the last few changes to the approximate image to reproduce the original. The advantage to this approach is that the user can quickly get a sense of the what the entire image looks like without having to wait for the whole thing to load.

Transparent gifs

Another attractive feature of the gif format is transparency. In a transparent gif, one color is designated as transparent. When the image is displayed, all pixels colored with the transparent color are instead set to the color of the background. This gives the effect of the background color "showing through" the image in certain places. Figure 11.1 shows images with and without a transparent background. Note how the oval in the image with the transparent background appears to just be sitting on the background, whereas the oval on the non-transparent background appears to be sitting on a rectangular box that is sitting on the background.

Fig. 11.1 - Transparent gifs have one color that is always changed to the background color, allowing the background to show through.

When you knock out the background behind an object in an image, you tend to get a "stairstep" pattern along the boundary, rather than a smooth curve. You can see this with the oval on the right in figure 11.1. To alleviate the stairstep pattern, you can use anti-aliasing. By anti-aliasing the image, you change the color of pixels on the boundary to a color halfway between the color inside the boundary and the color outside the boundary. By being colored with this middle-ground color, the boundary appears less jagged.


A number of the programs discussed in the "Graphics Programs" section of this chapter can create interlaced and transparent gifs.

Animation

You can create simple animations using gif files. The gif89a standard allows you to store the images that make up the animation in the same file. When a decoder detects a file with multiple images, it decodes and presents them in sequence to produce the animation.

Not all browsers have decoders that are sophisticated enough to properly present an animation. Version 2.0 of the Netscape Navigator does though. If you're using Netscape 2.0, you can check out the URL http://members.aol.com/royalef/gifanim.htm to see some sample gif animations and learn how to create them.

JPEG

The JPEG format refers to a set of standards for compressing full-color or gray-scale still images. JPEG's ability to work with full-color (16.7 million colors, 24 bits per pixel) images make it preferable to the gif format (256 colors, 8 bits per pixel) for working with photographs and nature-related art where the entire color spectrum is in play.

How JPEG Works

JPEG can handle so many colors in a relatively small file because it compresses the image data. You can control how big or small the image file ultimately is by adjusting the parameters of the compression. A highly compressed file can be very small, but the quality of the image on-screen will suffer for it.

When you decompress a JPEG image, there is always some amount of loss, meaning the image will not look exactly the way it did originally. Fortunately, JPEG's compression/decompression scheme is such that the lost image data is in the higher color frequencies where it is harder for the human eye to detect the differences. In spite of this loss, you can still use JPEG to achieve compression levels of about 10:1 or 20:1 without appreciable change in the image. This means you've changed from storing 24 bits per pixel to 1 or 2 bits per pixel - a very impressive savings! As noted above, you can take the compression ratios even higher, but as you do, the loss becomes more and more detectable.

Progressive JPEGs

One attractive feature of the gif format was the ability to interlace images. Interlacing reorganizes the image data so that as the file is read in, the image "fades in" over several passes, rather than just being read in from top to bottom. The analogous effect on the JPEG side is produced with progressive JPEG or p-JPEG. A machine displaying a p-JPEG presents a lower-quality approximation to the entire image after the first pass, followed by improvements in quality during subsequent passes. Thus, the user gets to see a rough version of the image right away and doesn't have to wait for the whole thing to display from top to bottom. The drawback of p-JPEG is that each pass over the image requires as much computational effort as the first, so the later passes are not necessarily faster.

In a Windows environment, you have a few options for converting to p-JPEG. The Independent JPEG Group (IJG) offers a series of command line programs for working with JPEG and p-JPEG files. You can download the source code from ftp://ftp.coast.net/SimTel/msdos/graphics/jpegsrc6.zip. Version 1.C of LView Pro (described later in this chapter) can also handle p-JPEGs.


There is no analogy for transparency in the JPEG format. The approach to transparency requires the selection of one color to be transparent. Because there can be data loss in JPEG compression/decompression, it's possible that a pixel colored with the transparent color may change to a slightly different color during the compression/decompression computations. Similarly, a pixel colored with a non-transparent color could become transparent and disappear. Either situation would undo the transparency effect you want to achieve.

Growing Acceptance

More and more browsers are warming up to the JEPG format and are able to display JPEG images without launching a helper application. Browsers that can fully support JPEGs and p-JPEGs include:

  • Netscape Navigator 2.0

  • Microsoft Internet Explorer 2.0 (under Windows 95)

  • Spyglass Enhanced Mosaic 2.1

  • UdiWWW 1.0.010

  • Java 1.0


An extensive list of frequently asked questions about the JPEG format can be found at http://www.cis.ohio-state.edu/hypertext/faq/usenet/jpeg-faq/top.html.

When Should I Use JPEG over gif?

There are a number of situations in which you might choose the JPEG format over the gif format. If preservation of more than 256 colors is important, you want to use JPEG. If you try to store a full-color image as a gif, the first thing that happens is that it gets knocked down to 256 colors. You can imagine how much different this might look when you consider that full, 24-bit color supports over 16 million colors!

Another factor is speed. A well-compressed JPEG version of an image is likely to be much smaller than a gif of the same image. Smaller file size means faster transmission time over the Internet. In some cases, once the file arrives at the browser or image decoder, you can further speed things up by configuring the decompression process to use reduced accuracy in doing the necessary calculations. However, this will increase data loss and reduce image quality.

A third reason is portability. With gifs, you're locked into 256 colors. JPEGs make no predetermination of how many colors to use, so it is more useful for transferring images among systems with different display hardware.

On the flip side, you'll want to use gifs for images with a few distinct colors, for black-and-white art like line drawings, and for images with sharp color changes. Most logos and icons found on Web pages fall into this category. Also, if you need an image with a transparent background, you have to use the gif format because there is no way to achieve transparency with JPEGs.

Graphics Tools

Some Web authors work in conjunction with graphics people who design and develop all of the images that go into a Web site. Other authors have to create the graphics themselves. If you ever find yourself in the latter situation, you'll need to know how to use one of the many graphics programs on the market. This section gives an overview of five such programs with emphasis on how they can help you create graphics for the Web.

UNIX Tools

The most common UNIX graphics tools are xpaint and xv. Xpaint is included with the X11R6 distribution, and is a simple paint program (see http://www.x.org). The descriptions below for Microsoft Paint work very well for xpaint too. Xpaint is "donateware" says the author, so if you like it, send him money or cookies or something.

Xv is a full image manipulation program. If xpaint is the poor man's Adobe Illustrator, xv is a poor man's Adobe Photoshop. Not only can it be used to view images, it has a very extensive array of color and palette manipulation tools, can convert into and from a large number of content types, and cut and paste regions of the image. Xv is available from ftp://ftp.cis.upenn.edu/pub/xv/.

Finally, Adobe PhotoShop is available on a couple UNIX platforms, and is the UNIX graphics creation tool of choice for most high-end graphics sites.

Microsoft Paint

Windows users have a basic graphics program right at their disposal in Microsoft Paint. Paint's main window is shown in figure 11.2.

Fig. 11.2 - Microsoft Paint is a basic graphics program that comes bundled with Windows.

Paint's tool palette lets you select one of many tools you can use to create and color graphical items and text. The lower four tools let you create rectangles with square or rounded corners, polygons, and ellipses. You can color the regions you create with the Pencil, Brush, Airbrush, or Fill tools.


To create circles in Paint, use the Ellipse tool while holding down the Shift key.

The Text tool enables you create pieces of text in various sizes and fonts. Be sure to turn on the Text Toolbar under the View menu when placing text as this will make changing text attributes easy.

The rest of Paint's tools are equally handy. If you just need a simple line or curve, the Line and Curve tools (found just above the Rectangle and Polygon tools, respectively) provide an easy way to produce one. The Magnify tool increases the magnification of the image so you can do detailed work on small parts of it. The Erase tool can erase anything you've drawn by moving the tool over the image and holding down the left mouse button.

At the bottom left of the Paint window, you'll find the color palette. Left-clicking on a color sets the foreground color to that color. Right-clicking a color does the same thing for the background. The default foreground/background combination is black on white.

Most of Paint's menu options are fairly standard or self-explanatory. The Image menu gives you options to flip, rotate, stretch, or skew your image and to modify its size and colors.

One useful feature that you find in Paint and most other graphics programs is a readout of the x and y coordinates of the pointer or cursor as you move it over the graphic. When you learn about imagemaps later in the chapter, you'll see that knowing certain coordinates on the image is critical to defining the hot regions on an imagemap.

For all of its features, Paint has one major drawback in the context of creating Web graphics: it can't save images in the gif or JPEG formats. If you want to use a Paint graphic on the Web, you need to convert it from a Windows bitmap to a gif or a JPEG using a format converter or a different graphics program.

LView Pro

LView Pro is a great little shareware program you can use to edit existing graphics or convert them to gif or JPEG format. It offers most of the same image manipulation features - such as flip and rotate - that Paint does, plus several other options that give you very fine control over image appearance.


The information on LView Pro presented here is based on the evaluation copy of version 1.C/32. You can download the latest version of LView Pro by pointing your browser to http://www.std.com/~mmedia/lviewp.html. A license costs US$30.00 plus US$5.00 for shipping and handling.

Figure 11.3 shows the LView Pro window along with its extensive tool palette. Almost every tool in the palette corresponds directly to one of LView Pro's menu options.

Fig. 11.3 - LView Pro's tool palette enables you to make modifications to most aspects of an image.

One nice feature is that LView Pro will let you open multiple images. This makes it easy to cut, copy, and paste objects from one image file to another. When you save an image, you can use LView Pro as a format converter and choose a format different from the original.

Notice that LView Pro doesn't have tools to create rectangles, polygons, and ellipses like Paint does. Indeed, the only LView Pro tool for creating anything is the Add Text tool. It stands to reason then that you'll probably have to use a different program to create your graphics. But what LView Pro lacks in ability to create, it makes up for with its ability to make very particular changes to an image.

LView Pro lets you change just about any facet of the image you could ever want. Tools on the palette call up dialog boxes to modify quantities like:

  • Image brightness and contrast

  • Red, Green, and Blue (RGB) color components

  • Hue, Saturation, and Value (HSV) values

  • Luminance and Chrominance (YCbCr) values

  • Transformation maps and filters for RGB color components

Other tools let you convert the entire image from color to grayscale or to its photographic negative.

Used in conjunction with a program that has more graphics creation capabilities, LView Pro is powerful editing tool that you can use to fine-tune the images you make for your Web pages.

Paint Shop Pro

Another good shareware program for graphics work is Paint Shop Pro from JASC, Inc. Paint Shop Pro handles many types of image storage formats, lets you do the most common image manipulations, and even comes with a screen capture facility.


The following information on Paint Shop Pro is based on the Shareware 3.11 version of the program. You can download this version from ftp://ftp.the.net/
mirrors/ftp.winsite.com/pc/win95/desktop/psp311.zip
. A license costs US$69.00 plus US$5.00 for shipping and handling.

Figure 11.4 shows an image loaded into Paint Shop Pro along with the many available tool panels that give you single-click access to Paint Shop Pro's functions. The Zoom panel lets you zoom in to magnifications as high as 16:1 and out to magnifications as low as 1:16. Tools on the Select panel sample colors, move the image around in the window, define a custom area of the image to clone or resize, and change the foreground and background colors. The Paint panel is a welcome addition to Paint Shop Pro that was not available in earlier versions. It supports 22 different tools that you can use to make your own graphics. These tools let you create brush, pen, pencil, marker and chalk effects; draw lines, rectangles and circles; fill a closed region with color; add text; and sharpen or soften part of an image. The Histogram window gives you a graphic representation of the luminance of all colors in the image, measured with respect to the brightest color.


You can toggle any of the tool panels on or off by using options found under the View menu.

Fig. 11.4 - Paint Shop Pro's tool panels give you easy access to common painting and image manipulation functions.

Paint Shop Pro is a versatile program that can open images stored in 25 raster (pixel-based) formats, including gif and JPEG, and 9 meta/vector (image components stored as geometric shapes that combine to produce the entire image) formats, including CorelDRAW!, Micrografx, and Ventura. However, it can only save in one of the raster formats. Nevertheless, Paint Shop Pro is still handy for converting to pixel-based formats. The Batch Conversion option under the File menu lets you select any number of files to convert to a new storage format.

TWAIN refers to a set of industry standards that allow graphics programs to work with image acquisition hardware like scanners. If you have a TWAIN-compliant scanner attached to your computer, you can use the File|Acquire option to scan in a new image. The Select Source option, also under the File menu, lets you choose what device you want to use for the acquisition.

Under the Image menu, you'll find options to do many of the standard manipulations like flipping the image upside down, creating a mirror image of an image, and rotating the images. The Image|Resample option allows you to change the size of an image with the jagged edges you get by standard resizing. You'll also find several effect filters under the Image menu that let you add or remove noise, enhance darker or lighter colors, and blur, sharpen or soften the image. You can even define effect filters of your own.

The Colors menu is host to many standard functions such as adjustment of brightness, gamma correction and RGB values, and conversion to grayscale or photographic negative versions of an image. You can also load, modify and save color palettes from the Colors menu. The Increase and Decrease Color Depth options allow you to change the number of colors being used to render the image.

One very useful feature of Paint Shop Pro is its screen and window capture facility. Options under the Capture menu let you capture the whole screen, a single window on the screen, the client area inside a window, or a user-define area. You can also choose whether or not the mouse pointer should be included in the capture and which hotkey will activate the capture.

Paint Shop Pro alone is a very capable image editing program ,but you can also purchase it bundled with Kai's Power Tools SE for added functionality. To order this combination package, contact JASC sales at 1-800-622-2793.

Micrografx Picture Publisher 6.0

Micrografx Picture Publisher 6.0 is an image creation and editing program that comes as part of Micrografx's ABC Graphics Suite. The Picture Publisher main window is shown in figure 11.5.

Fig. 11.5 - Micrografx Picture Publisher 6.0 is a feature-rich image creation and editing program.

To completely describe all of Picture Publisher's many features would fill several chapters, so the discussion here is limited to those features related to creating Web graphics. In addition to image painting capabilities that exceed those of Microsoft Paint and editing capabilities that at least match those of LView Pro, Picture Publisher supports the creation of Web graphics with features like:

  • Transparent and interlaced gif creation

  • Effect filters to sharpen or smooth image edges or to lighten or darken an image

  • Layers that act like sheets of acetate; you can place image objects on separate layers and then overlay them to produce the entire image

  • Anti-aliasing of object edges

  • Easy-to-create 3-D effects like drop shadows

  • Support for creating custom textures like wood grain or brushed steel

  • Filters that let you export your image in one of over 30 formats, including gif and JPEG

  • A highly customizable editing environment that lets you create your own "toolboxes" of tools, commands, and macros.

The other programs that come bundled with Picture Publisher 6.0 add value to the entire ABC Graphics package. ABC FlowCharter makes it easy to create diagrams and charts. Micrografx Designer is a useful graphics illustrator program and the ABC Media Manager puts over 30,000 clipart images, photos, and diagramming symbols at your fingertips.

For all you get, you'd probably expect that the Micrografx ABC Graphics Suite isn't shareware - and you'd be correct. However, a license for the entire package costs substantially less than what other stand-alone graphics programs might run you. Since software prices can change rapidly, you should consult your software dealer or Micrografx (1-800-671-0144) for the most up-to-date price information.


To learn more about the complete Micrografx product line, check out their newly redesigned Web site at http://www.micrografx.com/.

Adobe Photoshop

Adobe Photoshop sets the industry standards for both high-end imaging and importing other graphics. Additionally, there are versions of Photoshop that run on Macintosh, Windows, Silicon Graphics, and Sun platforms, making it the most powerful, cross-platform graphics application discussed in this chapter.

Just as with Micrografx Picture Painter, a full description of all of Photoshop's features would fill volumes. Photoshop supports many of the useful features noted for Picture Publisher like transparent and interlaced gifs, layers, anti-aliasing, drop shadows, and broad graphics file support, plus several others including:

  • Numerous plug-in programs that support custom effect filters and emerging image formats like progressive JPEG

  • Many options for dithering to lower color depths and different color palettes

  • Highly efficient memory management

  • A flawless interface with other Adobe products like Illustrator and PageMaker

Because it is so powerful, Photoshop doesn't come cheap. Depending on what platform you want to run Photoshop on, a single license can set you back almost $1000. Check with your software retailer or Adobe for current pricing.


For more information about Photoshop and other Adobe products, visit their Web site at http://www.adobe.com/.

Implementing Imagemaps

As noted at the start of the chapter, there are two kinds of imagemaps. The original kind is the server-side imagemap, in which the server does the work to determine what hot region the user clicked on. The newer variety is the client-side imagemap, in which the client makes this determination.

The major difference between the two approaches is where you find the information that defines the map hot regions and the URLs associated with those regions. For a server-side imagemap, the information is found in a map file that resides on the server. With client-side imagemaps, the information is embedded in the htmL code that produces the page the imagemap is on.

Server-Side Imagemaps

When a reader clicks on an image that is part of a server-side imagemap, the mouse coordinates relative to the upper-left corner of the image are sent to the server for processing by an imagemap script. The script looks at a map file to decide which hyperlink to follow based on the mouse coordinates.

In order for a server-side imagemap to work, several configuration steps are necessary. First, depending on what server software you use, certain imagemap support files must be present on your server. Second, you must create the graphic and determine the coordinates that define the various hot regions. These coordinates, along with the URLs associated with each hot region, are used to make up the map file. Finally, you need to set up the <IMG ...> tag that places the image so that the client knows it's dealing with an imagemap and what the name of the map file is.

Configuring Your Server for Server-Side Imagemaps

The NCSA, CERN, Netscape, and Windows httpds feature imagemap support, although there are differences among them. Important differences are noted as the section progresses. NCSA httpd requires two files for imagemap support. The first is a script called imagemap, which must be compiled for your machine and placed in the cgi-bin directory. CERN httpd requires a similar file. With Netscape and Windows httpds, the imagemap script is pre-installed and ready to go.

Second, for NCSA and CERN httpds, you need write permission to the imagemap.conf file in the server's conf directory. This file maps image names, which you create, to their associated map files. You have to add a line to this file for each new imagemap you create. The format of the imagemap.conf file is simple:

image_name : physical_path
The path to the map file is not a URL. It's the physical path on your system. A sample imagemap.conf is included below.

homepage : /maps/homepage.map
buttonbar : /maps/buttons.map
usmap : /maps/countries/us.map
The Netscape and Windows httpds do not require an imagemap.conf file.

Creating a Graphic and Defining Hot Regions

Standard htmL requires that the image you use for an imagemap be in the gif format. You can use any of the image editing programs discussed earlier in the chapter, possibly with a gif conversion tool, to make the gif file itself. The most difficult part of making an imagemap is mapping image coordinates to corresponding actions.

Imagemap scripts can process hot regions that are rectangles, circles, and polygons. Lines in a map file define these regions using the minimum number of (x,y) coordinates required to completely describe the region. Rectangles are defined by the coordinates of the upper-left and lower-right corners, circles by the coordinates of its center and a point along the circle itself, and polygons by the coordinates of its vertices. Coordinates are measured with respect to the upper-left corner of the image, which is taken to have the coordinates (0,0). The x-coordinate increases as you move to the right along the image and the y-coordinate increases as you move down the image.

Each line in a map file defines one hot region and specifies the URL associated with the hot region. For example:

rect URL upper_left(x,y) lower_right(x,y)
circle URL center(x,y) edge_point(x,y)
poly URL vertex1(x,y) vertex2(x,y) vertex3(x,y) ...

All URLs in the map file should be fully qualified.


The CERN imagemap facility uses the keywords rectangle, circle, and polygon instead of NCSA's and Netscape's rect, circle, and poly. In addition, the format of the map file is slightly different.

Netscape's imagemap script recognizes the keyword point in a map file as well. It is followed by the URL and the coordinates of the point.

You can also include a line in the map file beginning with the keyword default, which specifies what action to take if the coordinates of the mouse click are outside any hot region.


If you're doing imagemaps on a Netscape server, avoid using point and default lines in the same map file. If one or more point lines is specified, a click outside of a hot region is taken to be a click at the nearest hot point. This means that any default URL is disregarded.

Figure 11.6 shows a gif file to be set up with links to several government sites. The image contains a rectangle, a circle, and a pentagon (5-sided polygon) whose defining coordinates and associated URLs are shown in table 11.1.

Fig. 11.6 - A gif file to be linked to three different government sites.

Table 11.1 Defining Coordinates and URLs for Sample Imagemap
ShapeCoordinatesURL
Rectangle(36,70),(252,146)http://www.loc.gov/
Circle(214,219),(269,221)http://www.whitehouse.gov/
Polygon(389,61),(480,125),
(459,231),(334,230),
(305,131)
http://www.dtic.dla.mil/defenselink/


At this stage, your only option for finding the necessary coordinates is to use the pointer in your graphics program and read the coordinates from the program window. Later in the chapter, you'll learn about imagemap tools that let you create a map file without knowing the coordinates. These tools let you trace over shapes on your graphic and it figures out the coordinates for you.

Using the coordinates and URLs in table 11.1, you can write the map for the imagemap. In this case, the file would be:

rect http://www.loc.gov/ 36,70 252,146 
circle http://www.whitehouse.gov/ 214,219 269,221 
poly http://www.dtic.dla.mil/defenselink/ 
    389,61 480,125 459,231 334,230

Apache Internal Imagemap Handling

Apache, like the Netscape server and several others, is able to handle imagemaps internally. This means that no CGI process is required to service the imagemap request - one simply references the map file directly, and Apache itself translates the selected point coordinates into a new URL to redirect the browser.

This is done by setting the MIME type of your map files (which end with, say, .map) to a "special" MIME type using the "AddType" directive. In particular:

AddType application/x-httpd-imap map
The server, when asked to get this file, "knows" that file type is special and treats it with some internal machinery. This machinery is defined in the "mod_imap" module.

One would call this from htmL as any other imagemap file, but now one can do so locally, without a call to the imagemap CGI program. For example:

<A HREF="main-menu.map">
<IMG SRC="menu.gif"  ALT="Menu" ISMAP>
</A>
The URL's in "main-menu.map" can be relative URL's as well, making life easier for those who move directories around a lot. Because CGI is avoided, internal imagemaps are more efficient as well.

Optional: Linking to the Imagemap

If you'd prefer to use the CGI method for implementing imagemap functionality, use these instructions instead of the ones above, though the above method is strongly recommended over this one.

After you create a map file for an image, you must make it an anchor to include it in an htmL file, like this:

<A HREF="/cgi-bin/imagemap/govtsites">
<IMG SRC="images/govtsites.gif" ISMAP></A>
The hypertext reference must contain the URL to the imagemap script followed by a slash (/) and the name of the map defined in the imagemap.conf file. The actual picture is then included with the <IMG ...> tag. The <IMG ...> tag also includes the ISMAP attribute, indicating that the image placed by the tag is to be an imagemap.

For this example to work, there must also be a line in the imagemap.conf file pointing to a map file for the imagemap "govtsites." That line might look like this:

govtsites :/maps/govtsites.map

Client-Side Imagemaps

Having the server do the work to find out where the user clicked and where to send the user based on the click involves a lot of wasted resources. The client has to open another http connection to the server to pass the coordinates and get the response back regarding what URL to load next. The computations the server has to do to find out what hot region the user clicked on are straightforward and there's no reason they couldn't be done by the client. And slow transmission times between client and server means that users may have to wait quite a while from the time they click the mouse to the time the new URL is loaded.

Until recently, the compelling reason for having the server do the imagemap computations was because the map file data resided on the server. If there were a way to get this information to the client, then the client could do the computations and the imagemap process would become much more efficient. This is the spirit behind client-side imagemaps.

Currently, there are two proposals for implementing client-side imagemaps. Both provide a way to get the map file data to the client, but specifics of each approach are different. One proposal suggests the use of the <fig ...> ... </fig> tag pair with map file data contained in <A ...> tags between them. The other proposes a new tag pair - <MAP ...> and </MAP> - with <AREA ...> tags between them to contain the map file data.

Client-Side Imagemaps with the <fig ...> ... </fig> Tag Pair

The key to using the <fig ...> and </fig> tags for a client-side imagemap is that these tags can contain text that acts as an alternative to the image being placed by them. Thus, any text between the <fig ...> and </fig> tags is much like text assigned to the ALT attribute of the <IMG ...> tag. For example, the htmL:

<IMG SRC="logo.gif" ALT="Company Logo" 
    WIDTH=120 HEIGHT=80>
and

<fig SRC="logo.gif" WIDTH=120 HEIGHT=80>
Company Logo
</fig>
essentially do the same thing.

To implement the government sites map as a client-side imagemap with the <fig ...> and </fig> tags, you need to place the information previously found in the map file between these tags. This is done with the <A ...> tag as shown in listing 11.1.

Listing 11.1 Implementing the Government Sites Map

<fig SRC="images/govtsites.gif" WIDTH=530 
    HEIGHT=300>
<B>Select a government site to visit:</B>
<UL>
<LI><A HREF="http://www.loc.gov/" 
    SHAPE="rect 36,70,252,146">Library of Congress</A></LI>
<LI><A HREF="http://www.whitehouse.gov/" 
    SHAPE="circle 214,219,269,221">
The White House</A></LI>
<LI><A HREF="http://www.dtic.dla.mil/defenselink" 
    SHAPE="polygon 
        389,61,480,125,459,231,334,230,305,131"></A></LI>
</UL>
</fig>
The HREF attribute in each <A ...> tag contains the URL to load when the user clicks on a hot region and the SHAPE attribute contains the information needed to define each hot region. SHAPE is assigned to the shape of the hot region, followed by a space, and then followed by the coordinates that specify the region. Each number in the coordinate list is separated by a comma.

SHAPE also has a secondary function in this setting. If the image file specified in the SRC attribute of the <fig ...> tag is placed on the page, the browser ignores any htmL between the <fig ...> and </fig> tags, unless it is an <A ...> tag with a SHAPE attribute specified.

On the other hand, if the image is not placed, the browser renders the htmL between the two tags. The result for the htmL above is a bulleted list of links that can act as a text alternative for your imagemap. This is an important feature of client-side imagemaps done with the <fig ...> and </fig> tags: they degrade into a text alternative for non-graphical browsers, browsers with image loading turned off, browsers that don't support the <fig ...> and </fig> tags, or when the desired image file cannot be loaded.


Make sure that the alternative text between the <fig ...> and </fig> tags is formatted nicely into something like a list or a table. Users will appreciate this extra effort.


For the full scoop on the <fig ...> ... </fig> tag pair proposed for htmL 3.0, visit http://www.w3.org/pub/WWW/MarkUp/html3/figures.html.

Client-Side Imagemaps with the <MAP ...> ... </MAP> Tag Pair

While working on a version of Mosaic that could read from CD-ROM, people at Spyglass had an immediate need for client-side imagemaps. Their solution was to introduce a <MAP ...> and </MAP> tag pair to contain the hot region information previously found in map files. Each map defined by these tags is given a unique name so that it can be referenced from the <IMG ...> tag used to place the graphic for the imagemap.

To define a map for the government sites map above, you would use the htmL shown in listing 11.2.

Listing 11.2 Defining a Map for the Government Sites Map

<MAP NAME="govtsites">
<AREA SHAPE="RECT" COORDS="36,70,252,146" 
    HREF="http://www.loc.gov/">
<AREA SHAPE="CIRCLE" COORDS="214,219,269,221"
HREF="http://www.whitehouse.gov/">
<AREA SHAPE="POLYGON" 
    COORDS="389,61,480,125,459,231,334,230,305,131" 
    HREF="http://www.dtic.dla.mil/defenselink/">
</MAP>
The NAME attribute of the <MAP ...> tag gives the map information a unique identifier. The <AREA ...> tags between the <MAP ...> and </MAP> tags are used to define the hot regions and the URLs to which they link. You can have as many <AREA ...> tags as you like. If the hot regions defined by two <AREA ...> tags overlap, the <AREA ...> tag that is listed first gets precedence.

The <AREA ...> tag can also take a NOHREF tag, which tells the browser to do nothing if the user clicks on the hot region. Any part of the image that is not defined as a hot region is a NOHREF region, so if users click outside of a hot region, they won't go anywhere by default. This saves you from setting up an <AREA SHAPE="DEFAULT" ... NOHREF> tag for all of your maps.

The htmL used to define a map region can reside in the same file in which the <IMG ...> tag for the graphic lives or in an entirely different file. If the map definition is in the same file, you reference the map with the htmL:

<IMG SRC="images/govtsites.gif" 
    WIDTH=530 HEIGHT=300 USEMAP="#govtsites">
The USEMAP attribute in the <IMG ...> tag tells the browser it's dealing with a client-side imagemap and what the name of the map is. If you store all of your map information in a separate htmL file, the tag to link to the map would be:

<IMG SRC="images/govtsites.gif" WIDTH=530 HEIGHT=300
USEMAP="maps.html#govtsites">
Storing all of your maps in a single file is a good idea if you're placing the same imagemap on several pages. This is frequently the case with navigational button bars.


To read the Spyglass proposal for client-side imagemaps, visit the URL http://www.ics.uci.edu/
pub/ietf/html/draft-seidman-clientsideimagemap-01.txt
.

Using Client-Side and Server-Side Imagemaps Together

Client-side imagemaps are a great idea since they permit faster imagemap processing and enhance the portability of your htmL documents. Unfortunately, not all browsers support even one of the client-side imagemap approaches just described. Since you want to write htmL that is friendly to as many browsers as possible, you should consider combining server-side and client-side imagemaps whenever possible.

To combine a Netscape- or Windows-style server-side imagemap with the <fig ...> and </fig> tag approach to client-side imagemaps, you can modify the earlier example to be:

Listing 11.3 Using <fig... and </fig>

<fig SRC="images/govtsites.gif" WIDTH=530 
    HEIGHT=300>
<A HREF="maps/govtsites.map"><IMG 
    SRC="images/govtsites.gif"
WIDTH=530 HEIGHT=300 ISMAP></A>
<B>Select a government site to visit:</B>
<UL>
<LI><A HREF="http://www.loc.gov/" 
    SHAPE="rect 36,70,252,146">Library of Congress</A></LI>
<LI><A HREF="http://www.whitehouse.gov/" 
    SHAPE="circle 214,219,269,221">The White House</A></LI>
<LI><A HREF="http://www.dtic.dla.mil/defenselink" 
    SHAPE="polygon 
        389,61,480,125,459,231,334,230,305,131"></A></LI>
</UL>
</fig>
The second line in the htmL above is new. It places the same map graphic on the page and links it to the map file govtsites.map on the server. If the browser recognizes the <fig ...> tag and places the image it specifies, the additional line of htmL is ignored.

To combine a Netscape- or Windows-style server-side imagemap with the <MAP ...> and </MAP> tag approach, you can modify the earlier htmL to be:

<A HREF="maps/govtsites.map">
<IMG SRC="images/govtsites.gif" WIDTH=530 HEIGHT=300
USEMAP="#govtsites" ISMAP>
</A>
Flanking the <IMG ...> tag with <A ...> and </A> tags makes it point to the govtsites.map map file on the server. You need to include the ISMAP attribute in the <IMG ...> tag to let the browser know that the image is linked as a servers-side imagemap as well.


You can also link NCSA- and CERN-style server-side imagemaps to client-side imagemaps. Instead of the HREF in the <A ...> tag pointing directly to the map file, you need to make it point to the imagemap script.

Imagemap Tools

Whether you're creating a server-side or client-side imagemap, it can be cumbersome to determine and type in all of the coordinates of the points you need to define hot regions. Luckily, there are programs to help you through this process that will let you load your imagemap image, trace out the hot regions right on the screen, and then write the appropriate map file or htmL file to implement the imagemap. These next few sections describe some of these programs and tell you how to get them.

MapEdit

MapEdit 2.1 is a shareware imagemap tool produced by Boutell.Com, Inc. This version of MapEdit supports client-side images and images in the JPEG format, and cleans up a number of small bugs in the 2.0 release.

Using MapEdit is easy. To begin, select the Open/Create option under the File menu. The dialog box you see prompts you for several things. First, you need to specify if you are doing a server-side or client-side imagemap. If you choose server-side, you then need to select either NCSA or CERN formats and specify a name for the map file. If you choose client-side, you need to tell MapEdit the name of the file to which it should write the htmL code. Finally, you tell MapEdit the file containing image for the imagemap. When you click OK, the image file is loaded into the MapEdit window and you're ready to start defining hot regions.

You can choose Rectangle, Circle, or Polygon tools under the MapEdit Tools menu. Each tool lets you trace out a hot region shaped like the name of the tool. To use the Rectangle tool, point your mouse to the upper-left corner of the rectangular hot region and click the left mouse button. Then move your mouse pointer to the lower-right corner of the region. As you do, a black rectangular outline is dragged along with the pointer, eventually opening up to enclose your hot region (see fig. 11.7).

Fig. 11.7 - MapEdit lets you trace out a hot region using your mouse.

With the mouse pointer pointing at the lower-right corner, left-click the mouse again. When you do, you see a dialog box like the one shown in figure 11.8. Type the URL that is associated with the hot region you're defining into the dialog box, along with any comments you want to include, and click OK. MapEdit puts this information into the file it's building and is then ready to define another hot region or to save the file and exit.


Comments in a server-side imagemap map file are offset with a pound sign (#).

Fig. 11.8 - Once a hot region is defined, MapEdit prompts you for the associated URL and any comments.

MapEdit's Circle and Polygon tools work similarly. With the Circle tool, you place your mouse pointer at the center of the circular region (this is sometimes difficult to estimate!) and left-click. Then move the pointer to a point on the edge of the circular region and left click again to define the region and call up the dialog box. To use the Polygon tool, simply left-click on the vertices of the polygon in sequence. When you hit the last unique vertex (i.e., the next vertex in the sequence is the first one you clicked), do a right-click instead to define the region and reveal the dialog box.


If you're ever unhappy with how your trace is coming out, just press the Esc key to erase your trace and start over.

Other MapEdit Tool menu options let you move an entire hot region, add or remove points from a polygon, and test the imagemap file as it currently stands. The Edit Default URL option under the File menu lets you specify a default URL to go to if a user clicks on something other than a hot region.


You can download MapEdit 2.1 by directing your browser to http://www.boutell.com/mapedit. After a 30 day evaluation period, you must license your copy of MapEdit at a cost of US$25.00. Site licenses are also available. Educational and non-profit users do not have to pay for a license, but they should register their copies of MapEdit.

Web Hotspots

Web Hotspots 2.0 is a shareware imagemap tool developed by Keith Doty at 1Automata. Web Hotspots supports both server-side and client-side imagemaps and can load graphics in both gif and JPEG formats. Figure 11.9 shows the government sites graphic loaded into the Web Hotspots window. You can see in the figure that Web Hotspots provides you with buttons that let you change between tracing tools quickly.

Fig. 11.9 - You can access Web Hotspots tools quickly using buttons in the main window.

In addition to the usual rectangle, circle and polygon tools, you also get a freeform region tool that lets you define unsually-shaped hot regions. As you define a region, Web Hotspots shades it for you, making it easy to see in relation to objects in the graphic. The shading feature is illustrated in figure 11.10.


Web Hotspots converts a freeform region into a many-sided polygon, so the line for the freeform region in the map file or <AREA ...> tag in the htmL file will start with the keyword polygon. You can see all of the vertices in the many-sided polygon that describes the freeform region in figure 11.10.

Fig. 11.10 - Web Hotspots shades a hot region as you define it, making it easy to see.

Once a hot region is defined, you can type in the associated URL into the URL edit box near the bottom of the window.

Web Hotspots offers a number of other useful features beyond its basic functionality including:

  • A context-sensitive help box

  • A zoom feature that lets you increase or decrease the size of the image

  • A testing mode that supports live testing over the Internet (you need to have WinSock installed to do this)

  • Image rescale and rotate options

  • The ability to move a hot region to the front of the map file or htmL file, giving it precedence over the other regions


You can download an evaluation of Web Hotspots 2.0 from http://www.cris.com/~automata/hotspots.shtml. After 30 days, you can remit US$49.00 plus US$5.00 shipping and handling to purchase a license. The US$49.00 price is valid through May 1, 1996.

Map THIS!

Map THIS! is a freeware imagemap tool written by Todd C. Wilson. It only runs on 32-bit Windows platforms, but that's about the extent of its limitations. Map THIS! can help you with server-side and client-side imagemaps and can load images in both the gif and JPEG formats. Figure 11.11 shows the Map THIS! main window with the government sites graphic loaded.

Fig. 11.11 - Map THIS! is a freeware imagemap tool that supports server-side and client-side imagemaps on graphics in both gif and JPEG format.

Most of Map THIS!'s features are accessible through buttons in the main window. The rectangle, circle, and polygon tools occupy the first three buttons in the second row. The circle tool is particularly nice because you drag out the circle from one point on the circle to the point that is diametrically opposite it, rather than trying to start on the exact center of the circle. As you use one of the tools, you get instructions on what to do next in a box at the lower left of the window. You can enable the shading feature to make the hot regions you define easier to see.

The Area List, shown in figure 11.11, is a floating box that you can activate to show the regions you've defined and what URLs they're linked to. You can also turn on a grid pattern to help you measure out hot regions with greater accuracy.

Map THIS! lets you work on multiple images. You have the choice of cascading or tiling the windows that contain the images. When it's time to save your work, you can save in CERN or NCSA format for server-side imagemap map files or in htmL format for client-side imagemaps. Other useful features of Map THIS! include:

  • Adding points to or deleting points from polygons

  • Color support all the way up to 24-bit color

  • Zoom in and out

  • A Preferences window in which you can set the map type and color choices for outlining and shading hot regions

  • A Mapfile Information window in which you can specify a default URL, the map title, your name, and other descriptive comments

  • Context-sensitive menus accessible by right-clicking the mouse


To download the latest version of Map THIS!, point your browser to http://www.ecaetc.ohio-state.edu/tc/.

Testing

A great feature of the imagemap tool programs is that you can use them to test your imagemaps. MapEdit's test mode presents the imagemap graphic to you and lets you click on it. If you click on a hot region, the URL dialog box opens and displays the URL associated with the region on which you clicked. Web Hotspots' test mode allows you to test your imagemap right on the Internet. As long as you have an active WinSock layer, Web Hotspots will fetch the URL that goes with the hot region on which you clicked. The Map THIS! testing mode opens up a completely separate window (see fig. 11.12). As you move your mouse pointer over a hot region, its corresponding URL shows up in the box at the bottom of the screen.

Fig. 11.12 - As you move your mouse over a hot region in the Map THIS! test window, the URL you'd jump to shows up at the lower left.

If none of these programs are available to you, you'll have to put your map or htmL files on your server and test them with a browser. You can make small changes to these files using a simple text editor, if needed.


If you're testing a client-side imagemap with a browser, make sure the browser can implement the approach (<fig ...> or <MAP ...>) that you used.


QUE Home Page

For technical support For our books And software contact support@mcp.com

Copyright © 1996, Que Corporation

Table of Contents

10 - htmL Editors and Tools

12 - htmL Forms