Screen Size to adjust an image?

They have: 5,633 posts

Joined: Jan 1970

It's possible to detect the browsers screen resolution and adjust an image according to the results?
Thanks.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Check these out:

from irt.org
http://tech.irt.org/articles/js035/index.htm#4
http://developer.irt.org/script/285.htm
http://developer.irt.org/script/1166.htm
(related)

javascriptkit
http://javascriptkit.com/script/cut135.shtml
http://javascriptkit.com/script/cut12.shtml
(related)

You can spin a script together that adjusts your image height with something like document.images['myimage'].width = screen.width * (factor_of_screen_width)

Smiling

Busy's picture

He has: 6,151 posts

Joined: May 2001

just remember a lot of people disable javascript because of pop ups etc so don't rely on it

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

I haven't looked...But do the scripts take account of resizing windows, maximising, different browsers DOM's?

...Just some considerations for you Smiling

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

JeevesBond wrote: I haven't looked...But do the scripts take account of resizing windows, maximising, different browsers DOM's?

Yep. Smiling For active resizing, you'll want to call the function every x milliseconds to update your data. DOMs are a little trickier -- iirc, NS uses screen.availWidth whereas IE uses screen.width, so you'd have to write for both.

Although Suzanne is correct, I might add that resizing bitmaps per window area can work if it is used reasonably (not active resizing, only check onLoad). In this case, one could use GD or similar to resize the image for possibly improved quality. Still won't be terribly efficient, though. Wink

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

For reference, allowing the browser to adjust the image will universally result in poor results if the image is a bitmapped image. If it's a vector image (Flash, et cetera), then the technology that displays them will adjust the images correspondingly without you needing to do anything.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.