HTMLGoodies
The ultimate html resource
Earthweb.com


About the Double-Underlined Links


Become a Partner




Search Clipart.com:



internet.commerce















HTML Goodies : Primers : HTML Primer: Basic HTML: Manipulating Images

HTML GOODIES TO GO NEWSLETTER


Other Related Newsletters

Basic HTML: Manipulating Images


By Joe Burns

(with updates by editorial staff)

Use these to jump around or read it all
Placement On Page
Aligning Text With Images
Changing Image Size
The <HR> Command

Just as I thought a primer, Primer #3, was required explaining how to manipulate text, I also think one is needed on how to manipulate images. Believe it or not, manipulating images is much the same as manipulating text. So, here we go.


Placement On The Page

First let's worry about placing the image somewhere on the page. The default is justified to the left. If you write an image tag on a page, the image will pop up hard left.

If you want to have an image placed in the center of the page, you use the CSS, 'text-align: center;' as described in Primer #3.

But how do we get the image to the right of the page? Well, how did we get text to the right? By adding the 'text-align: right;', right? Could it be we do the same thing here? Why yes, it could.

Here's the format:

<div style="text-align: center;"><IMG SRC="image.gif" ALT="image"></div>

Here's what you get using "sally.gif" in place of "image.gif":


Aligning Text With Images

Images don't always stand alone. You will often want text alongside them. Here you will float the image, and then allow the text to wrap around it. Clever stuff!

Here are the formats:

<div style="float: left;"><IMG SRC="sally.gif"> text text text</div>

<div style="float: right;"><IMG SRC="sally.gif"> text text text</div>

And here's what it all looks like:

This is text wrapping around an image floated to the left. We will fill in lots of text here just to make the point...

This is text wrapping around an image floated to the right. It's worth telling you now that you can't float an image to the center. Odd really, but then, floating to the center usually involves a two column layout,

You may notice I've used an extra CSS property, 'clear:left;' on the second one.
<div style="float: right; clear: left;"><IMG src="/images/sally.gif"></div>
This is to ensure that the next float is clear of the one above it. You can use left, right or both as values.


Changing Image Size

To begin this discussion, let me state that images on a computer are not like photographs. Computer images are made up of a lot of little colored dots. They're known as picture elements or "pixels" for short. So, just remember that during this part of the Primer, numbers refer to pixels rather than inches, or centimeters, or whatever. When I say pixels, I'm talking little colored dots.

Every image is made up of pixels. The more pixels per inch the image has the better, and more detailed, the image will appear. Of course, that also means the image will take up a whole lot more bytes on your hard drive. You're going to find that most images on the Web are 72 and 100 pixels per inch. Yes, there are other settings, but 72-100 is a good trade-off between loss of detail and bytes required.

Okay, so every image is made of pixels. This means that you can also denote an image by number of pixels. For example, the "sally.gif" image is 97 pixels high by 64 pixels wide. How do I know that? I have an expensive graphics program that tells me so. How would you know? Without a specific program, you wouldn't. You'll have to play around with the numbers in these commands a little bit, but it's easy to do.

You might also want to open the image by itself in the Netscape Navigator browser window. Do that by choosing OPEN FILE under the FILE menu. When the picture pops up, look at the title bar along the very top. The height and width should be there.

Of course, you can also go out onto the Web and surf around for a shareware graphics program. My personal favorite is PaintShop Pro. You get it for free for 30 days and then it's like $80 or so to get it for good. There are even a few open source alternatives out there.

Here's what you do. Denote to the image command how many pixels high by how many pixels wide you want. The "sally.gif" image is 64X97 pixels. If I want the image to appear smaller, I will ask for the pixels to be smaller, say 30X55. If I want it bigger, I would set the pixels larger, say 100X250. Just remember form. If you make the image smaller or larger, you must keep the same general square, rectangle, or whatever, form.

Of course, if I want to, I can totally distort the picture.

Here's the coding:

<IMG HEIGHT="##" WIDTH="##" SRC="image.gif">

Notice the HEIGHT and WIDTH attributes nestled right where the ALIGN command went before. You will replace the "##" with a number of pixels for height and width. Here are the three examples:

This is normal size:

This is 30X55:

This is 100X250:

This is 100X23:

However, if the image is bigger than you need you are better off making it smaller in a graphics package, simply because it will be a smaller file size, so your page will load faster.

Making it bigger isn't really a great idea either, because it will tend to go pixelly, if I can call it that!

Putting the actual dimensions of the image in is a good idea, because the page will load with the correct amount of space allocated to the images - otherwise the image will download and the page will move down and rearrange for every image that downloads.


The <HR> tag

The WIDTH command also works on the <HR> command, except you'll use percentages. Watch this:

<HR WIDTH="40%"> gives you this:


<HR WIDTH="64%"> gives you this:


You get the idea, yes?

That wraps it up. Try these in the comfort of your own home under the supervision of an adult. If you are an adult, then find a kid who can program the VCR to help you along.

Placement On Page
Aligning Text With Images
Changing Image Size
The <HR> Command

Tools:
Add htmlgoodies.com to your favorites
Add htmlgoodies.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

IT Management Networking & Communications Web Development Hardware & Systems Software Development Earthwebnews.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers