Image references in HTML

In HTML images are separated from documents. Documents contain references to image files in the place where images should appear inside a document. An image reference describes the location and name of respective image file as well as how it is to be rendered. The actual images are stored separately in image files and loaded dynamically when documents are displayed.

An image reference in HTML is expressed by an img tag having the reference attribute and additional attributes such as in

<img src="images/picture.jpg" border=0 width=100 height=200>

The image reference attribute (attribute src) can be either an absolute or relative path and file name expression. The other attributes specify information about how the image is to be displayed such as image width and height or how much space between text and image is to be rendered.

Absolute references

An absolute reference is an expression containig the full path and name of an image file such as in

file:/C:/data/documents/myDoc/images/picture.jpg

Absolute image references should be avoided as they need to be changed whenever the image file is moved to another location.

Relative references

A relative reference has path and file name information relative to the location a HTML document is stored. An expression such as

images/picture.jpg

inside a document stored as

c:\data\document\myDoc\doc.htm

would mean the same as the absolute reference expression from previous paragraph. The main difference however is that whenever the document and image file are moved to a new location together, the relative reference can remain unchanged.

Resolving relative references

In SimplyHTML's implementation of image support only relative references are used. To resolve relative image references, class HTMLDocument allows to specify a base location with method setBase. When a document is loaded, its source path is passed to method setBase as the the base directory. When a new document is created, a temporary directory is set with method setBase.

In both cases all relative references are resolved against the base directory set with method setBase.