|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
How can I find the height/width of an image?
I have a popup where I scale the image to a smaller size than original. Iused to set the img tag to width="50%". This no longer works in the current edition of IE on MS. On Mac IE it still does. Go figure.
So... I now need to set the width to a fixed value. I also need to adjust the popup to the value of the image height + some value to allow for text etc. The quandry? How can I get the height and width of an image into a variable for use on the calling asp page. TIA - Heinz |
|
#2
|
|||
|
|||
|
You'll need to use some kind of third party component to get the size of an image. You can find components here:
http://www.aspobjects.com/ASP_Compo..._Charts/Images/ There are some free ones there that you can use, however, you'll need access to your server to be able to install any kind of com object. You may need to find a host that has such third party com object support. |
|
#3
|
|||
|
|||
|
Never say never (or can't be done)
We should qualify our answers with "well i haven't seen it done on the server side anyway with an external component". Come on guys your always temping fate when you say never. try this Code:
<html> <head> <title></title> </head> <body> <img src="b.gif" id="x"> <input type="button" value="fred" onclick="w = document.all.x.width; h = document.all.x.height; document.all.x.width = (w / 2); document.all.x.height = (h / 2); alert(document.all.x.width + ' '+ document.all.x.height);"> </body> </html> The mind just boggles at the posibilities! The reason I save the width and height in variables is because if you just go Code:
document.all.x.height = (document.all.x.height / 2); The image is scale in both the width and height (which is probably what you wanted, but slightly counter intuative) I think for Netscape you need to use document.getElementById['x'].height or something like that. Well this is how IE6 seems to behave anyway. You may be able to formulate some develish way of having a hidden window which goes window.blur() and submits the javascript width and height values back in a form ( which is submitted in the onload event handler) so your asp can generate the proper width and height attributes for your img tag. Thats if you want to have the server side involde for some reason like saving the size in a database. Just one more though on image sizes you could always open the image file as a binary stream and look for the height and width fields in the image file header. With most common graphics file formats they will just be two or four byte numbers at some fixed offset from the beginning of the file. If enough people say it can't be done in pure asp, I might even be tempted to write the code and submit it here just to prove them wrong (an make me look really cool) If your image is not on a filesystem your asp can get to ie. you only have access via a url, you could always try using microsofts xmlhttp object to get the image first, if you have or can install it on you webserver.
__________________
-- ngibsonau |
|
#4
|
|||
|
|||
|
error: width/height undefined
ngibsonau, when i run your code and test the values of w and h i get the output that they are undefined, how do you explain that?
maybe you could show how to open the file as a byte stream, cause i want to save the width and height to a database for my program thanks for any help... |
|
#5
|
|||
|
|||
|
works like a charm... thanks!!!
|
|
#6
|
|||
|
|||
|
ref my last comment
i should add that the w and h are undefined when i generate the page using asp. why does it work in just normal html but not when i create the html page with asp?
any thoughts? |
|
#7
|
|||
|
|||
|
not sure what you men, this is what i did:
<html> <script language = "Javascript"> function figureout() { var w var h w = document.all.x.width h = document.all.x.height alert("pic width="+document.all.x.width +" pic height="+ document.all.x.height); document.all.x.width = (w / 2) document.all.x.height = (h / 2) alert("pic width="+document.all.x.width +" pic height="+ document.all.x.height); } </script> <body> <img src="1.jpg" id="x"> <input type="button" value="Shrink" onclick= "figureout();" </body> </html> |
|
#8
|
|||
|
|||
|
figured it out myself, thanks for trying though, now i can read file names from a file, dynamically put them into a html page and then dynamically shrink them down to a thumb, i must say thanks though to "ngibsonau" who got me started on the right track.....
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > How can I find the height/width of an image? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|