Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Sizing - Interesting question

Status
Not open for further replies.

westcoaststyle

Programmer
Oct 15, 2001
81
US
I'm bringing images in dynamically and I want to size them on the page irregardless of what size they are in the database.

I want to know if there's a way for me to set the width to a specific pixel value and the height will follow suit without me setting the height value.

Say I have an image that's 100x100. If I set width="50", I want the height to automatically know that it should be 50.

Another example: I have an image that's 100x300. I tell the width="50", the height sets itself to 150.

These are just examples so I will not always have images that are the same size so I can't just set height="50%" (I've thought of that).

Any ideas?

Thanks!
 
Since you're doing this dynamically, just add a field to the db (assuming you use one) saying which form you're using. Default behavior resizes the image's height proportionally as compared with the width or vice versa, so for that, you merely set one. Like this (PHP):

<?
if($row[&quot;form&quot;]==&quot;resize&quot;){
print('<img width=&quot;50&quot;>');
}
?>

For the other, if the field says that the size needs to be equal, something like this:

<?
if($row[&quot;form&quot;]==&quot;equal&quot;){
print('<img width=&quot;50&quot; height=&quot;50&quot;>');
}
?>

Combine the code:
<?
($row[&quot;form&quot;]==&quot;equal&quot;)?$ss='height=&quot;50&quot;':$ss=&quot;&quot;;
print('<img width=&quot;50&quot; ' . $ss . '>');
?>

Of course, PHP may be different than what you use, but the logic's the same :).

Rick

-----------------------------------------------------------
RISTMO Designs
Arab Church
Reference Guides
 
can i have ur code (database)?

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top