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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limit the size of an image 1

Status
Not open for further replies.

stranger123

Programmer
Apr 16, 2006
76
GB
Hi,

<img src="
How to limit the width and height of the image? I don't mind to cut it or put it in a box with scroll bars, but I don't want to use <img src=" width="...">

Any suggestion?
 
Since css cropping ( is not widely supported yet in the modern browsers, the only thing you could do is put it in a div that has a limited width and height and put [tt]overflow: auto;[/tt] on the div to make it scroll (or overflow: hidden; if you want to just cut it).
 
Vragabond,
Thank you. I am going to have a try.

ChrisHunt,
The image URLs will be posted by users and I need to limit the size.
 
Vragabond,

I have just tested and that works, thank you.

Here is the only problem, say
<div style="width:300px; height:200px; overflow:auto;">
when the image height is 100px, how to let the div change to 100px automatically?
 
Or, if you have access to a server side language you could use that to resize the image to the size you want.
It's quite easy with PHP.

Using that method you are actually creating an image that is the correct size, rather than squashing a large one down.
If you take an 800 x 800px image and put it on your page sized to 100 x 100px , it's STILL and 800 x 800 image and has the same filesize.

Alternatively, if you actually resample the image as I described above, then you are putting a 100 x 100 image on your size, with a correspondingly smaller filesize.

<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Ham and Jam - British & Commonwealth forces mod for Half Life 2
 
Foamcow,

Thank you for your imformation.
In my case, the image is only a url, it from the external site.
 
Vragabond,

Actualy, your suggestion is fine. Thanks a lot.
 
if the image is simply a url from another site there is no way you are going to be able to find the physical dimensions of the image.
So using width & height in HTML or CSS are your only options.


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Chris said:
If the image is simply a url from another site there is no way you are going to be able to find the physical dimensions of the image.

You can - using my handy FAQ, "Detecting the dimensions of an image client-side": faq216-5781

While it's not a substitute for doing this server-side, it will still give a the image dimensions client-side for 95% of users.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
That is an interesting code. I will have a try. Thank you for your work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top