EIW Fall 2004 Lecture Notes

HTML and Images


The IMG tag

You can include images in your HTML document using the IMG tag. The actual images themselves can be anywhere on the WWW, so your web page can include images that come from another site. The IMG tag has one required attribute - the SRC attribute specifies the URL that contains the image. Typically the URL will indicate a static file that contains either a GIF or JPG image (two standard file formats for images)

.

A simple example of an IMG tag and what this looks like when the browser renders it:

Here is my image: <IMG SRC=cookie.gif>
  

Here is my image:

There are a number of optional attributes to the IMG tag that can alter how the image is rendered by the browser, some are listed below.

Images as links

Images can be hyperlinks, all you need to do is put the IMG tag between the <A> tag and it's end tag </A>. Here is an example:

Press the cookie to go to cookie.com
<A href="http://www.cookie.com">
<IMG SRC=cookie.gif>
</A>

rendered will look like this:

Press the cookie to go to cookie.com

IMG tag optional attributes:

Image File Format: GIF vs. JPG

The image file formats supported by most browsers are GIF, JPG (pronounced jaypeg), and PNG (Portable Network Graphics). There are differences you might want to be aware of.

GIF JPG PNG
Max. # of colors 256 Tens of thousands True Color
Compression Lossless compression
(doesn't compress much, but nothing is lost)
Great compression,
but with some loss
Lossles compression
Transparency Yes NO Yes
Interlacing Yes NO Yes
Animations Yes NO NO

There have been licensing issues associate with the GIF format, although it is often used for icons, drawings and anything requiring animation. JPG is typically used for photographs. PNG is used for lots of things...