HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [46]
The alt attribute is required on all images if you want to validate XHTML Strict.
Additionally, the tag is an inline tag, so it needs to be embedded inside a block-level tag, like a
or
Choosing an Image Manipulation Tool
You can’t just grab any old picture off your digital camera and expect it to work on a Web page. The picture might work, but it could cause problems for your viewers. It’s important to understand that digital images (any kind of images you see on a computer or similar device) are different from the kind of images you see on paper.
An image is worth 3.4 million words!
Digital cameras and scanners are amazing these days. Even moderately priced cameras can now approach the resolution of old-school analog cameras. Scanners are also capable of taking traditional images and converting them into digital formats that computers use. In both cases, though, the default image can be in a format that causes problems. Digital images are stored as a series of dots, or pixels. In print, the dots are very close together, but computer screens have larger dots. Figure 6-4 shows how the ship image looks straight from the digital camera.
My camera handles pictures at 6 megapixels (MP). That’s a pretty good resolution, and it sounds very good in the electronics store. If I print that picture on paper, all those dots are very tiny, and I get a nice picture. If I try to show the same picture on the computer screen, I see only one corner. This actual picture came out at 2,816 pixels wide by 2,112 pixels tall. You only see a small corner of the image because the screen shots for this book are taken at 1024 x 768 pixels. Less than a quarter of the image is visible.
Figure 6-4: Wow. That doesn’t look like much.
When you look at a large image in most browsers, it’s automatically resized to fit the page. The cursor usually turns into some kind of magnifying glass, and if you click the image, you can see it in its full size or the smaller size.
Some image viewers take very large images and automatically resize them so they fit the screen. (This is the default behavior of Windows’ default image viewer and most browsers.) The image may appear to be a reasonable size because of this feature, but it’ll be huge and difficult to download in an actual Web page. Make sure you know the actual size of an image before you use it.
Although shrinking an image so that it’s completely visible is obvious, there’s an even more compelling reason to do so. Each pixel on the screen requires 3 bytes of computer memory. (A byte is the basic unit of memory in a computer.) For comparison purposes, one character of text requires roughly 1 byte. The uncompressed image of the ship weighs a whopping 17 megabytes (MB). If you think of a word as five characters long, one picture straight from the digital camera takes up the same amount of storage space and transmission time as roughly 3,400,000 words. This image requires nearly three minutes to download on a 56K modem!
In a Web page, small images are often shown at about 320 x 240 pixels, and larger images are often 640 x 480 pixels. If I use software to resample the image to the size I actually need and use an appropriate compression algorithm, I can get the image to look like Figure 6-5.
Figure 6-5: The resized image is a lot more manageable.
The new version of the image is the size and file format I need, it looks just as good, and it weighs a much more reasonable 88 kilobytes. That’s 2 percent of the original image size.
Although this picture is a lot smaller than the original image, it still takes up a lot more memory than text. Even this smaller image takes up as much transmission time and storage space as 1,600 words! It still takes 10 seconds to download on a 56K modem. Use images wisely.
Images are great, but keep some things in mind when you use them:
♦ Make sure the images are worth displaying. Don’t use a picture without some good reason because each picture makes your page dramatically slower