Click to See Complete Forum and Search --> : using img.width in asp


solomon_13000
06-21-2006, 12:11 PM
I did a combination of asp and jscript. Parsing a value from asp to jscript is working fine. However I intend to use the width value on asp. How is it done?

<script language="JavaScript">

function testing(pix)
{
img = new Image()
img.src = pix
alert(img.width)
}

</script>

<%
Dim m
m = "http://www..com/db/Upload/photos/nature/06331_30.jpg"
%>

<html>
<head>
<title>Hello World</title>
</head>
<body onLoad="testing('<%=m%>')">
<%
response.write "I intend to use the width value over here"
%>
</body>
</html>

lmf232s
06-21-2006, 12:30 PM
solomon,
I had actually typed up a response to your original post this morning but i lost all the text and did not fell like typing it again. So well do it in this post.

Asp does not have an ability to get an image width or height.

Although you may want to check out this article http://www.4guysfromrolla.com/webtech/050300-1.shtml.

They have actually developed a way to determine the image properties using asp by reading the bytes of the image and then doing some calculations based on that.

That being said almost everything else that you want to do can be achieve using ASP w/ a combination of FSO to iterate the images.

Let me know how it goes as im interested in the end result as well post back if you have any problems.

lmf232s
06-21-2006, 12:35 PM
Solomon,
Sorry i actually did not really read this post as at first glance it was kind of like your original.

From reading this post you actually have most of it done you just want to get the width property to ASP.

What i can see you doing is creating a hidden input field and then from javascript write that value to the hidden field. Now you can get the value of the hidden field in ASP by requesting the field.


<script language="JavaScript">

function testing(pix)
{
img = new Image()
img.src = pix
alert(img.width)
document.form1.hidImageWidth.value = img.width;
}

</script>

<body>
<form name=form1 method=post>
<input type=hidden name=hidImageWidth value="">


Then to get the value

Request.Form("hidImageWidth")

See if that helps.

solomon_13000
06-21-2006, 12:56 PM
I tried this but no results were displayed for response.write Request.Form("hidImageWidth")


<script language="JavaScript">

function testing(pix)
{
img = new Image()
img.src = pix
alert(img.width)
document.form1.hidImageWidth.value = img.width;
}

</script>

<%
Dim m
m = "http://www.mutaiyas.com/db/Upload/photos/nature/06331_30.jpg"
%>

<html>
<head>
<title>Hello World</title>
</head>
<body>

<form name=form1 method=post>
<input type=hidden name=hidImageWidth value="">
</form>

<script language="JavaScript">
testing('<%=m%>')
</script>

<%
response.write Request.Form("hidImageWidth")
%>

</body>
</html>

russell
06-21-2006, 01:00 PM
ya gotta submit the form

lmf232s
06-21-2006, 01:23 PM
What are you trying to do. I think there are a couple of other options we can try but need to know exaclty what your trying to achieve and what your going to do w/ this width when you get it.

solomon_13000
06-21-2006, 01:36 PM
I finally got it running, but I am getting a result of 800'' with a '' and not just 800.


<script language="JavaScript">

function testing(pix)
{
img = new Image()
img.src = pix
document.form1.hidImageWidth.value = img.width;
}

</script>

<%
Dim m
m = "http://www.mutaiyas.com/db/Upload/photos/nature/06331_30.jpg"
%>

<html>
<head>
<title>Hello World</title>
</head>
<body>

<form name=form1 action="newpage.asp" method=post>
<input type="hidden" name="hidImageWidth" value="">
<INPUT TYPE="SUBMIT" NAME="name" VALUE="label">
</form>

<script language="JavaScript">
testing('<%=m%>')
</script>

<%
response.write Request.Form("hidImageWidth")
%>"

</body>
</html>

solomon_13000
06-21-2006, 01:40 PM
I am actually trying to make an image fit a screen size. If the user choose to see the actual size of the image simply click on the image and the original image size will be displayed.

lmf232s
06-21-2006, 02:04 PM
you can remove the ".

If this value is in asp you can do this

Replace(string, string 2 remove)

Replace(Request.Form("hidImageWidth"), """)

solomon_13000
06-22-2006, 06:35 AM
now it works fine. :)