Contributed by Enrique Bengoechea
The following macro simplifies the process of inserting images because it automatically
computes the width and height of the image. It also allows adding any attribute to the tag:
Macro to insert images 1: Source Code |
Download:
img1.htp
(134 bytes) |
1| .macro IMG
2| <IMG src="$1" \
3| width="&image_width('$1')" height="&image_height('$1')"\
4| .if qq~$+~
5| $+>
6| .else
7| >
8| .endif
9| .endmacro
|
- Explanation
- The conditional in lines 4 to 6 are required if you don't want an ugly whitespace
between the last attribute and the closing "greater-than" sign.
- Usage
- Invoke the macro as
<.IMG filename optional_attributes>">, e.g.
<.IMG logo.gif alt="iMatix Logo" hreflang="en">
.
In the above macro you must specify the images directory everytime you use it, unless images
are stored in the same directory as the htmlpp document. You could easily modify the macro
definition to specify the absolute filepath for the directory where you store images. But if you
prefer to use relative directories, the following macro may prove useful:
Macro to insert images 2: Source Code |
Download:
img2.htp
(190 bytes) |
1| .macro IMG
2| <IMG src="&relpath('$(img-dir)$1')" \
3| width="&image_width('$(DIR)/$(img-dir)$1')" height="&image_height('$(DIR)/$(img-dir)$1')"\
4| .if qq~$+~
5| $+>
6| .else
7| >
8| .endif
9| .endmacro
|
- Explanation
- In order for the macro to work, you must define the variables
$(img-dir)
and
$(DIR)
before using it. $(DIR)
would be the base directory of the website,
and $(img-dir)
the images directory relative to the base directory.
- Usage
- For the following structure:
/
|
-- website
|
-- about
|
-- images
You would make:
.define DIR /website
.define images images/
and then use, for a page in directory "about",
<.IMG logo.gif alt="iMatix Logo" hreflang="en">
which would produce
<IMG sr="../images/logo.gif" width="50" height="20"
alt="iMatix Logo" hreflang="en">