190 likes | 404 Views
HTML Images. Inserting a Graphic. Images can be displayed in two ways: as inline images or as external images . an inline image displays directly on the Web page and is displayed when the page is accessed by a user
E N D
HTML Images Instructor: A. Burns
Inserting a Graphic • Images can be displayed in two ways: as inline images or as external images. • an inline image displays directly on the Web page and is displayed when the page is accessed by a user • an inline image can be placed on a separate line in your HTML code, or it can be placed directly within a line of text • An external image needs an external application to be viewed Instructor: A. Burns
Inline Images • Three graphic file types are supported by today's browsers. • GIF (AKA Compuserve GIF) - Graphic Interchange Format • JPEG - Joint Photographic Experts Group • PNG - Portable Network Graphics Instructor: A. Burns
GIF • GIF files are best used for images that have broad areas of flat color and are highly defined. • Supports transparency and animation • Supports a maximum of 256 colors called 8-bits. • They are cross platform • They are compressed Instructor: A. Burns
GIF • The great advantage of GIF is that you can choose to have one color that is transparent • That is, lets the background color of a page show through part of the image • Another important advantage of GIF is that you can create animation with them. Instructor: A. Burns
GIF • GIF are best for • Images with large areas of solid, flat color e.g • Logos • Cartoons Instructor: A. Burns
JPEG • JPEG • JPEG can contain 16.7 million colors (called 24-bit) as to 256 colors for GIF • JPEG are best for photographs, watercolor images. • JPEG are file sizes are smaller Instructor: A. Burns
JPG • JPEG files are best used for images that require many colors such as photographs. • JPEG has a higher compression ratio but it is a "lossy" compression (compression sacrifices some image data in reducing file size). Instructor: A. Burns
GIF Instructor: A. Burns
GIF • Problem? Instructor: A. Burns
JPEG • Solution Instructor: A. Burns
Inserting Images • <img src="name and location of image file"> • Adds an image • We usually put images in a separate folder • E.g. <img src=“images/myImage.gif” • The image file resides on the web server (shrike) and has a644 permission. Instructor: A. Burns
Aligning Images • To insert an image • <img src=“images/myImage.gif"> • To right-align an image: <img align=“right” src=“images/myImage.gif"> • You can also left-align the image: <img align=“left” src=“images/myImage.gif"> Instructor: A. Burns
ALT attribute <img src="mlk.gif" alt=“M.L. King’s picture” width=“336” height=“400”> • Allows you to provide a text equivalent for the object. • Useful for… • Browsers that do not display images • Text readers for blind, color-blind, low-sighted • Search engine bots (the alt attribute makes sure that they won't miss important sections of your pages) Instructor: A. Burns
Bandwidth Limitations • Image files consume more bandwidth than text files • Users who access the Internet via telephone lines will have to wait for image files that are 100KB or larger • Whenever possible, use image files no larger than 30-40KB Instructor: A. Burns
Battling Bandwidth Limitations • Always specify height and width attributes for all your images so the browser can “work around” each image while it is downloading. • TIP: To find an image dimension: open it using a Web browser, then select Properties on the File Menu. Instructor: A. Burns
Scaling Images • Rescale the image by changing its WIDTH and HEIGHT attributes. • Preserve the aspect ratio (height-to-width ratio) otherwise the image gets distorted. Divide or multiple the dimensions by the same factor. • Scaling down an image DOES NOT reduce its bandwidth requirements. To reduce the file size, you need to compress the image. Instructor: A. Burns
Example of image scaling <html> <head><title> Image Scaling </title></head> <body> <img src=“cat.jpg” width=“320” height=“266”> <img src=“cat.jpg” width=“160” height=“266”> <img src=“cat.jpg” width=“320” height=“133”> <img src=“cat.jpg” width=“160” height=“133”> </body> </html> The image size is 320x266 px. How will a browser display these images? scaling example Instructor: A. Burns