JavaScript? Set HTML Image tags Width and height dynamically

Hi, I have the task of creating an asp page that generates a standard email newsletter. The HTML Image Width and Height tags need to be set to the actual image size (no they haven’t been set to a standard size on the server) as they are read in via an while loop. I believe in ASP, you are out of luck for a function that does this, so Javascript may be the way forward. Ideally something like in the <IMG> tag can you call a javascript function like width=“javascript:Getwidth(<%=myImage.jpg%>)” ??

My code is as follows for the image inside an anchor tag, as you can see i tried the min and max style properties for the image, but this does not set them exactly. e.g. width=“120px” height=“94px”, which is what is required. The image dimensions are not all the same, code below:

<a href=“;%=objRS(“id”)%&gt;”><img id=“<%=objRS(“image_small”)%>” style=“border:3px solid transparent; float:left; vertical-align:top; min-height:80px; max-height:100px; min-width:100; max-width:130px;” src=“;%=objRS(“image_small”)%&gt;” alt=“Read full story - <%=objRS(“title”)%>” /></a>

Thanks for any help on this

You can use javascript to get the actual image width and height

var myPic = new Image();
myPic.src = 'pic1.jpg';

but I am not aware of any email client programs that support javascript.

but if you want to do it server side, I would be surprised if ASP did not have a way of getting the height and width of an image. PHP has a function GetImageSize() which returns an array of image properties including width and height.

I just did a quick google of “get image size asp” and got a listing of urls that may or may not be of help to you. I’m not an asp programmer so they don’t mean much to me.

Just letting the forum know that I solved this issue with ASP in the end, I know this is a javaScript Forum, I’m just stating how I solved my problem. I included the attached file in the website, renaming it to a .asp extension. Then including this file in the code page, like so: <!–#INCLUDE FILE=“imgsize.asp”–>

Then using the method “gfxSpex” in the file to pass the path etc of image and return the width and height etc. I used the “w” and “h” variables in the image tag, which is being passed around a while loop, like below:

dim newsImage
newsImage = objRS(“image_small”)
call gfxSpex(“g:\websites\websitename\htdocs\images\” & newsImage, w, h, c, strType)%>
<a href=“;%=objRS(“id”)%&gt;”><img id=“<%=objRS(“image_small”)%>” width=“<%=w %>” height=“<%=h %>” style=“border:3px solid transparent; float:left; vertical-align:top;” src=“;%=objRS(“image_small”)%&gt;” alt=“Read full story - <%=objRS(“title”)%>” /></a>

This sets the images width and height tags the the specific height and width of each image. These properties were required to be set, as the generated “web page” was required to be copied into Group Mail for the sending of a newsletter, and images can appear small etc if the properties are not set to specific dimensions.

Thanks for the replies