HTML 4 - User's Guide
The IMG element
1. SAMPLES
1.1 An old style page with images
Here is a sample HTML page coded in the old style. The IMG elements stand out in blue.<HTML> <HEAD> <TITLE>TULIP</TITLE> </HEAD> <BODY bgcolor="aqua"> <center><b><font color="red" size="+1">TULIPS</font></b></center> <IMG src="../Images/tulip_1.jpg" align="left" width="200" alt="TULIP"> The tulip is a bulbous plant of the genus <i>Tulipa</i> of the family <i>Liliaceae</i>. Its name derives from the Turkisk word <b>tulbend</b> which derives from the Persian <b>dulband</b> meaning <i>turban</i>,<IMG src="../Images/tulipField.jpg" align="right" height="190" alt="TULIP FIELD"> from the shape of the expanded flower.<br> It is cultivated on a large scale in Holland where its culture accounts for a sizable part of the national product.<br> Worlwide tulips are cultivated as garden flowers. </BODY> </HTML>To see how the page is displayed, please click here".
1.1.1 Image identification The src attribute specifies the URI of the image. In the example the images are in the local machine; the URIs ("../Images/tulip_1.jpg" and "../Images/tulipField.jpg") are the files relative directory paths. |
1.1.2 Image placement The <IMG> element can be inserted anywhere in the text. It is placed against the left side of the page by the "left" value of the "align" attribute; the line where the image starts is the first one with sufficient space after the point where the <IMG> element is inserted. The value "right" of attribute "align" places the image against the right border of the page. |
1.1.3 Image scaling The attributes "width" and "height" set the size of the image. You need specify only one of the dimensions. The image is scaled to that dimension, with the other dimension automatically adjusted to preserve the original proportion. |
1.1.4 Fallback information The "alt" attribute defines the information that will be displayed if the browser cannot render the image defined by the src attribute. These are "TULIP" and "TULIP FIELD" in the above examples. |
1.2 Image placement using the float property
This example shows how the image can be placed using the style sheet.
<HTML>
<HEAD>
<TITLE>THE MOON</TITLE>
<LINK rel="stylesheet" type="text/css" href="../styles/HatayBook.css">
<STYLE>IMG.left {float:left; margin-bottom:1em; margin-right:1em;}</STYLE>
</HEAD>
<BODY>
<b>TO THE MOON</b>
<p>
<IMG src="../Images/MoonLandscape.bmp"
class="left" width="150" height="125" alt="Moon landscape">
Art thou pale for weariness<br>
Of climbing heaven and gazing on the earth,<br>
Wandering companionless<br>
Among the stars that have a different birth, --<br>
And ever changing, like a joyless eye<br>
That finds no object worth its constancy?
<p>
<TABLE>
<TR><TD width="50%"><TD><b>Percy B. Shelley</b>
</TABLE
</BODY></HTML>
1.2.1 The style sheet In the present case, the style sheet is the content of element <STYLE> which is in the content of element <HEAD>, along with the <TITLE> and <LINK> elements. In this style sheet:
| ||||||||||||||||||||||||||||||||||||||||||
1.2.2 The class attribute The class attribute (class="left") define a class of <IMG> elements; this class is referenced in the style sheet by the name of the element ("img"), with the class name ("left" in the present example) appended to it with a connecting dot ("img.left"). | ||||||||||||||||||||||||||||||||||||||||||
1.2.3 The other attributes The other attributes was already seen in the above example. 1.3 Sensitive image This is an example of a page with a sensitive (client side) image.<HTML> <HEAD><TITLE>THE COCK</TITLE></HEAD> <BODY> <MAP name="cock"> <AREA shape="circle" coords="96,90,20" href="ILLcock.html"> <AREA shape="rectangle" coords="70,0,158,30" href="../Images/Hose-pipe.html"> <AREA shape="polygon" coords="150,0,170,0,225,192,192,192" href="../Images/bamboos.jpg"> </MAP> You can click on the cock, the bamboo stalk or the pipe-hose<br> <IMG src="../Images/cock.jpeg" width="250" height="192" usemap="#cock" alt="A cock" > </BODY> </HTML>The image is displayed as this:
![]() The map is defined by the <AREA> elements in the content of the MAP element. The name="cock" attribute assigns the name "cock" to the map.
The image is defined by the <IMG> element which references the "cock.jpg" image file contained in directory "Images".
<TABLE><TR><TD> <A href="http://127.0.0.1:21000/books/HTML/Here"> <IMG ismap src="../Images/apple.bmp"> </A> <TD> Please <b><font color="blue">CLICK ON ANY POINT</font></b> of the image<br> The PIXEL COORDINATES of the point where you click will be sent to the server </TABLE> The page will show as this:
The IMG element is set in the contents of an A element, and is marked with the ismap attribute. A click on any point in the image will send the pixel coordinates of the point to the internet address specified by the href attribute of the A element. A Web Server is expected to be waiting for information at this address. In the above example, the specified Internet address is port 21000 of the local host. In the classes/web directory, we have a JAVA class that monitors this port, and writes out information received there, both to the current window, and to a file called form.txt, in the same directory. To see this information, before clicking on the image, you can run this class which is named web.MyServer:
1.5 Further examples A further examples of using the <IMG> element is in the SampleObject-1b.html file.2. USAGE 2.1 Image presentation By default, image is placed in-line with the surrouding text; e.g. these lines:This is an in-line image. <IMG src="../Images/flower_2.jpg" width="210" height="160">It heightens the line to its height, and is placed in the flow.will generate the following display:
This is an in-line image.
To place the image to the left or to the right of the display space (which can be the page or a cell in a table -- as defined by the <TD> element), and let the surrounding text flow on its side, you can use:
The align attribute can have the values:
When only one of the dimension is specified, the other is adjusted in proportion. 2.1.3 Image margins and borders
2.2 Client side versus server side A click on a client side (sensitive) image is handled by the client browser; a client side image is associates with a map which relates figures of the image to target pages; the browser will load the target page associated to the clicked on figure. A click on a server side image is to be handled by the server; the browser will send the pixel coordinates of the clicked point to the server; it is up to the user to set up a process on the server side to handle the reveived information.
Client side (sensitive) images are defined by the usemap attribute that references a map: Server side (sensitive) images are specified by the ismap attribute that has no value; its presence signals a server side map; the IMG element must be placed in the contents of an A element which defines the address where the information is to be sent:
2.3 Supported formats The IMG element support image formats such as implied by the extensions:- .art - .bmp - .gif (pronounced "jif") - .jpeg - .jpg - .png (pronounced "ping") 3. SYNTAX 3.1 Overview An <IMG> element has the general format:<IMG attributes-and-values>with no end tag </IMG>. 3.2 Attributes The usual attributes are:
contents introduction reference index previous next |