HighDots Forums  

Image scaling

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Image scaling in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stephane D'Alu
 
Posts: n/a

Default Image scaling - 10-19-2003 , 08:09 AM







Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.

The two ideas I had were:
- <img src="toto.jpg" style="max-width: 200px; max-height: 200px;"/>
but it doesn't keep the ratio

- <div style="width: 200px; height: 200px;"><img src="toto.jpg/></div>
but the image flow outside the div


Sincerly,

--
Stephane D'Alu

Reply With Quote
  #2  
Old   
David Dorward
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 08:21 AM






Stephane D'Alu wrote:

Quote:
Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.
No

--
David Dorward http://dorward.me.uk/


Reply With Quote
  #3  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 11:18 AM



Stephane D'Alu <sdalu (AT) sdalu (DOT) com> wrote:

Quote:
Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.
Maximum with respect to what? You can set width: 100%, and by leaving
height unset, you're asking browsers to maintain the proportions.

But browsers generally do an awful job in scaling images. Anything but
a very simple ornament probably gets distorted.

--
Yucca, http://www.cs.tut.fi/~jkorpela/


Reply With Quote
  #4  
Old   
jake
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 11:32 AM



In message <slrnbp538f.1895.sdalu (AT) rork (DOT) sdalu.com>, Stephane D'Alu
<sdalu (AT) sdalu (DOT) com> writes
Quote:
Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.

The two ideas I had were:
- <img src="toto.jpg" style="max-width: 200px; max-height: 200px;"/
but it doesn't keep the ratio

- <div style="width: 200px; height: 200px;"><img src="toto.jpg/></div
but the image flow outside the div


Sincerly,

img src="toto.jpg" width="100%"


--
Jake


Reply With Quote
  #5  
Old   
Stephane D'Alu
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 12:53 PM



On 2003-10-19, Jukka K. Korpela <jkorpela (AT) cs (DOT) tut.fi> wrote:
Quote:
Stephane D'Alu <sdalu (AT) sdalu (DOT) com> wrote:

Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.

Maximum with respect to what? You can set width: 100%, and by leaving
height unset, you're asking browsers to maintain the proportions.
I want to be able to specify the maximum width AND height of a block
and have the image fitting in it but keeping its aspect ratio (in fact
an easy way to create a thumbnail gallery in a browser).

And of course the size is specified in px, em or ex, but not a percentage.

Sincerly

--
Stephane D'Alu


Reply With Quote
  #6  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 01:05 PM



Stephane D'Alu <sdalu (AT) sdalu (DOT) com> wrote:

Quote:
I want to be able to specify the maximum width AND height of a
block and have the image fitting in it but keeping its aspect ratio
Did you consider the practical problems of scaling that I mentioned,
before you started wanting that?

Anyway, you can do that only by first computing the width or height.
That is, CSS won't do that for you.

Quote:
(in fact an easy way to create a thumbnail gallery in a browser).
Why didn't you say that? Just don't scale them. Use a good thumbnailing
program to generate the thumbnails for you, in fixed size.

Quote:
And of course the size is specified in px, em or ex, but not a
percentage.
Well, I don't see how that relates. You can set width:100% even when
the enclosing block has size specified that way.

--
Yucca, http://www.cs.tut.fi/~jkorpela/


Reply With Quote
  #7  
Old   
jake
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 06:28 PM



In message <Xns9419C3B191624jkorpelacstutfi (AT) 193 (DOT) 229.0.31>, Jukka K.
Korpela <jkorpela (AT) cs (DOT) tut.fi> writes
Quote:
Stephane D'Alu <sdalu (AT) sdalu (DOT) com> wrote:

Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.

Maximum with respect to what? You can set width: 100%, and by leaving
height unset, you're asking browsers to maintain the proportions.

But browsers generally do an awful job in scaling images. Anything but
a very simple ornament probably gets distorted.

Actually, I find that most browsers (IE/Mozilla/Netscape/Opera) do quite
a good job of re-scaling the image downwards (i.e. automatic 'down
sampling'). The secret seems to be to produce the image big enough so
that, for most common browser size settings, the browser is *always*
re-sampling downwards.

The larger size of the image means that the compression need to be
higher, and so the image is probably not quite as good as a fixed-sized
one -- but it's really not too bad at all for all practical purposes.

It works well with flexible pages, so that as the screen shrinks, the
image shrinks to maintain the same proportion (which may or may not be a
good thing, depending upon what your aiming for).

regards.
--
Jake


Reply With Quote
  #8  
Old   
Christoph Paeper
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 07:09 PM



*Stephane D'Alu* <sdalu (AT) sdalu (DOT) com>:
Quote:
Do you know if it is possible to have an image to be scalled
to a maximum width/height, but with keeping its aspect ratio.
Sure, most likely in your image manipulation program or with certain
scripting/programming languages, but not in pure CSS or HTML.

--
A bus station is where a bus stops,
a train station is where a train stops,
on my desk I have a work station...


Reply With Quote
  #9  
Old   
Eric Bohlman
 
Posts: n/a

Default Re: Image scaling - 10-19-2003 , 10:05 PM



jake <jake (AT) gododdin (DOT) demon.co.uk> wrote in
news:KtbknkYR4xk$Ew3+@gododdin.demon.co.uk:

Quote:
Actually, I find that most browsers (IE/Mozilla/Netscape/Opera) do quite
a good job of re-scaling the image downwards (i.e. automatic 'down
sampling'). The secret seems to be to produce the image big enough so
that, for most common browser size settings, the browser is *always*
re-sampling downwards.

The larger size of the image means that the compression need to be
higher, and so the image is probably not quite as good as a fixed-sized
one -- but it's really not too bad at all for all practical purposes.

It works well with flexible pages, so that as the screen shrinks, the
image shrinks to maintain the same proportion (which may or may not be a
good thing, depending upon what your aiming for).
It should not, however, be used to create thumbnails. The distortion then
is usually severe, download time is *badly* affected, and browsers (it's
happened to me with both MSIE and Opera in various versions) tend to scroll
slowly or jerkily, or even crash, when viewing pages with lots of
"dumbnails."

I guess the point is that browsers should not be relied upon to resize
images *drastically*.


Reply With Quote
  #10  
Old   
Stephen Poley
 
Posts: n/a

Default Re: Image scaling - 10-20-2003 , 02:27 AM



On 20 Oct 2003 03:05:38 GMT, Eric Bohlman <ebohlman (AT) earthlink (DOT) net>
wrote:

Quote:
jake <jake (AT) gododdin (DOT) demon.co.uk> wrote in
news:KtbknkYR4xk$Ew3+@gododdin.demon.co.uk:

Actually, I find that most browsers (IE/Mozilla/Netscape/Opera) do quite
a good job of re-scaling the image downwards (i.e. automatic 'down
sampling').
Perhaps usually true, but I have met some cases where browser shrinking
also produced pretty mediocre results.

Quote:
It should not, however, be used to create thumbnails.
Absolutely not. It destroys the point of having thumbnails in the first
place.

And if you want really good thumbnails, you probably don't want to take
the whole image anyway, but rather select a squarish portion containing
the main feature(s) of the image.

--
Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.