ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 25th, 2003, 07:27 PM
Heinz Heinz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: Langley, BC Canada
Posts: 35 Heinz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 29 sec
Reputation Power: 7
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

Reply With Quote
  #2  
Old April 28th, 2003, 07:25 AM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
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.

Reply With Quote
  #3  
Old May 17th, 2003, 04:21 AM
ngibsonau ngibsonau is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 138 ngibsonau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #4  
Old July 16th, 2003, 03:39 PM
webtutor webtutor is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 3 webtutor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #5  
Old July 17th, 2003, 04:00 AM
Agarash Agarash is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 53 Agarash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 35 sec
Reputation Power: 6
works like a charm... thanks!!!

Reply With Quote
  #6  
Old July 17th, 2003, 05:15 PM
webtutor webtutor is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 3 webtutor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #7  
Old July 18th, 2003, 12:42 AM
Agarash Agarash is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 53 Agarash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 35 sec
Reputation Power: 6
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>

Reply With Quote
  #8  
Old July 19th, 2003, 02:55 AM
webtutor webtutor is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 3 webtutor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.....

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > How can I find the height/width of an image?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway