Graxeon Posted January 1, 2009 Share Posted January 1, 2009 I made this new website: http://www.top-media.it.tc/ I need to figure out how to make the image fit within all browser dimensions while still keeping the aspect ratio of whatever content I put in there (let's say 1000x1000 lowers to 100x100 if that's the size of the user's browser). Does anyone know the code for this? I tried searching for it for an hour but can't find one Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/ Share on other sites More sharing options...
ToonMariner Posted January 2, 2009 Share Posted January 2, 2009 not that easy - you could use svg (scaleable vector graphics) but I think olnly opera supports that at the mo - not checked other browsers for a bit so ff3 and safari could now support them. in the current state of affairs your only option is to use some js to detect viewport size and serve out different images sized accordingly for each... Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-727777 Share on other sites More sharing options...
Graxeon Posted January 2, 2009 Author Share Posted January 2, 2009 Why is this not easily done? Tables do it by using 100% on width + height...why not with images? Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-727834 Share on other sites More sharing options...
Graxeon Posted January 2, 2009 Author Share Posted January 2, 2009 I tried something with DIV layers and a style code snippet but it didn't work. Anyone know of a way of doing this? Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-728080 Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 I'm fairly sure that this would be completely JS. Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-728099 Share on other sites More sharing options...
Graxeon Posted January 2, 2009 Author Share Posted January 2, 2009 Oh...alright. Can someone move this to the JS forum, please? Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-728141 Share on other sites More sharing options...
RussellReal Posted January 4, 2009 Share Posted January 4, 2009 <img src="whatever.jpg" id="image" /> <script type="text/javascript"> function resizeImage(image) { vh = window.innerHeight; vw = window.innerWidth; if (""+vh+"" == "undefined") vh = document.documentElement.offsetHeight; if (""+vw+"" == "undefined") vw = document.documentElement.offsetWidth; if (image.width > image.height) { cRat = image.height / image.width; image.height = vh * cRat; image.width = vw; } else if (image.height > image.width) { cRat = image.width / image.height; image.height = vh; image.width = vh * cRat; } else { image.height = Math.min(vh,vw); image.width = Math.min(vh,vw); } } resizeImage(document.getElementById("image")); </script> Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-729329 Share on other sites More sharing options...
ToonMariner Posted January 4, 2009 Share Posted January 4, 2009 ????? why do all that? if you are just going to scale the image then width="100%" would do the job. if you wanted a nice un-pixelated image at different resolutions then you would have to produce and image of a size for each range of window resolution - otherwise the design will look amateurish. Link to comment https://forums.phpfreaks.com/topic/139118-auto-resize-to-users-browser/#findComment-729479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.