Dynamically Resizing Images
One of the biggest criticisms facing Dynamic HTML(DHMTL) in relation to Flash is DHTML’s seeming inability to scale pages relative to a browser’s dimensions. To overcome this problem, three central areas need to be focused upon:
- Dynamic Font Scaling.
- Layer Resizing.
- Element Resizing
In this article we are going to investigate how to dynamically resize an image. But before we do, lets understand some of the previous techniques used in an attempt to try and accommodate differing browser dimensions.
Developers typically went one of four ways.
- Conditionally passing different size images based on screen resolution.
- Opening a new fixed sized window.
- Asking the user to switch screen resolutions.
- Not bothering at all.
Each of these methods has its drawbacks, for example, many users object to a new fixed size window being opened. Developers typically hate making four or five different size versions of the same image and then finding that if a user was not in a certain screen resolution that the fluid nature of their pages quickly fell apart. I know personally I am not amenable to switching screen resolutions just to see someone’s page and I am sure many are like-minded. Finally not caring at all really must shed a poor light on the “developer” that takes this route.
Recently, I discovered a method that allows for the dynamic resizing of images as well as other page elements that doesn’t rely on passing multiple images. In all honesty even this method has its drawbacks. For one thing it requires, extra coding to make pages fluid. Another drawback is that to actually see the best results with this method, a higher than typical image resolution is needed. For example, if using a background, rather than making the background 800*600, something akin to 1152 * 864 is needed. The golden rule here is to scale down not up, as scaling up results in poor image quality. The obvious disadvantage is that this method leads to increased kbs.
However, if care is taken in image construction with particular emphasis on image compression while maintaining a reasonable image quality, then it is quite a feasible and viable method to use. Additionally, it saves the developer time, because only one image has to be made rather than many versions of the same image. On top of this developers have an image that scales appropriately to different browser dimensions. While the following method is by no means perfect, I am still working on perfecting it; I do have a strong belief that it’s a definite positive step in the right direction.
Lets begin this sojourn by first looking at the completed script: