Friday, June 09, 2006
Its been a long while since I've blogged code.

I have dynamic images (photos to be precise) coming in.  They can be various sizes.  I have a limited width area on my web page in which to display the photo.  I don't want to stretch the small images but I don't want large images to mess up my layout.  I require a clientside solution for maximum image <img> width without affecting thos images that aren't violating the threshold.

                <script>
                function maxImage(img, width){
                     //copy to new image so it will work in ie
                    var newImg = new Image();
                    newImg.src = img.src;
                    var iWidth = newImg.width;
                    var iHeight = newImg.height;
                    if( iWidth > width ){
                        var iRatio =  iWidth / width;
                        img.width = width;
                        img.height = iHeight / iRatio;
                    }
                }
                </script>

                <img border="0" src='<%# Eval("SomeDynamicImageUrl") %>' onload="maxImage(this,250);"/>

For years I have said, "can't be done."  Reinforces my philosophy: never say never

6/9/2006 7:28:54 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback

Theme design by Jelle Druyts

Pick a theme: