Quick html question

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Quick html question

Post by pinehead18 »

Is their a way in html to set the max height and width for an image. But if the image isn't that size it does not make it fit it? It just wont let it go past the max width and height?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Sort of.

On the img tag itself, you can set height/width tags:

Code: Select all

<img src="somefile.png" width="100" height="100">
However, it doesnt PREVENT the image from being more than those dimensions - it simply uses a fairly crappy resize function to force it to fit into those dimensions for the display. (Meaning, the client still could be downloading a 1024x768 size image, but displaying it as 100x100.. much bandwidth loss).

It does prevent an image from breaking a pixel-perfect layout, but there are many (including me) that would argue that a pixel-perfect layout is inherently bad for a variety of reasons.

But thats how to use html to resize the image to a locked height/width. :)
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Yeah, thats what i have been doing. What i was wanting to accomplish is not lock the image unless it reaches that widht/height see what i mean?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

pinehead18 wrote:Yeah, thats what i have been doing. What i was wanting to accomplish is not lock the image unless it reaches that widht/height see what i mean?
Ah. Hmm. You could instead do..

Code: Select all

<table>
<td>
<tr height = "200px">
<img src="somefile.png" height="100%">
</tr>
</td>
</table>
I beleive that will allow the picture to be displayed up to 200px, but not above. Granted, I havent tested it, but .. I think the concept is sound to do what you are asking for.

I also think you could do the same with just css (and probably much better than the above hack), but I cant 'freehand' css just yet.. not that good at it yet.
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

as you can tell i can barely free hand html lol so i think the above will work. I'll let you know how ti goes as soon as i put it in the sytem
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

<tr height = 50px><td align=center><img src=http://l.com/pics/$mainpic></tr></td>

That is what i have.. it dones't seem to make the pic go smaller..
Suggestions?
jtc970
Forum Commoner
Posts: 38
Joined: Sun Jan 18, 2004 11:49 pm

Post by jtc970 »

<table>
<td align=center>
<tr height = "50px"><img src=http://l.com/pics/$mainpic>
</tr></td>
</table>
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

I set it to 10px to see if it would resize the image and it didn't.

Any other ideas?
Post Reply