INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Determine the Width and Height of an External Image

Determine the Width and Height of an External Image

(OP)
Does anyone know if there is a way, in classic ASP, to determine the height and width of an external image, that is not located on the server, and store these values in seperate classic ASP variables?

For example, I would like to determine the height and width of the following image without having to save it locally and then store each value into separate ASP variables:

http://i.ebayimg.com/00/s/OTM1WDExMDk=/z/2xQAAOSwZ...

Thanks for your help

RE: Determine the Width and Height of an External Image

Quote (Krus1972)

Does anyone know if there is a way, in classic ASP, to determine the height and width of an external image, that is not located on the server, and store these values in seperate classic ASP variables?

There isn't.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Determine the Width and Height of an External Image

Hello - this might be a bit of a late comment but I thought you might be interested in a possible workaround.

1. Load image into DIV with javascript
2. Measure image using javascript
3. Send dimensions to ASP page to save values to database

CODE

<html>
<head>
<script>
function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

function getImage(imageURL) {
    document.getElementById('imageDiv').innerHTML = "<img id='myImage' src='" + imageURL + "' />";
}

function measureImage() {
    var myImage = document.getElementById('myImage');
    document.getElementById('imageWidth').value = myImage.width;
    document.getElementById('imageHeight').value = myImage.height;

    sendMeasurementsToServer();
}

function sendMeasurementsToServer() {
    xmlhttpSendMeasurementsToServer = GetXmlHttpObject();
    if (xmlhttpSendMeasurementsToServer == null) {
        alert("Your browser does not support XMLHTTP!");
        return;
    }

    var imageURL = document.getElementById('imageURL').value;
    var imageWidth = document.getElementById('imageWidth').value;
    var imageHeight = document.getElementById('imageHeight').value;

    url = "savemeasurements.asp?ImageURL=" + imageURL + "&ImageHeight=" + imageHeight + "&ImageWidth=" + imageWidth;
    url = url + "&sid=" + Math.random();
    xmlhttpSendMeasurementsToServer.onreadystatechange = function() {
        if (xmlhttpSendMeasurementsToServer.readyState == 4) {
            var aspResponse = xmlhttpSendMeasurementsToServer.responseText;
            alert(aspResponse);
        }
    }
    xmlhttpSendMeasurementsToServer.open("GET", url, true);
    xmlhttpSendMeasurementsToServer.send(null);
}
</script>
<head>
<body>
Enter image URL
<input type="text" id="imageURL" style="width:500px;padding:10px;">
<input type="button" value="Measure" onclick="getImage(document.getElementById('imageURL').value); measureImage();">
<div id="imageDiv"></div>

Client-side measurement
<br>
Width:<input type="text" id="imageWidth">
Height:<input type="text" id="imageHeight">


</body>
</html> 

And make a file called savemeasurements.asp

CODE

<%
ImageURL=Request.QueryString("ImageURL")
ImageHeight=Request.QueryString("ImageHeight")
ImageWidth=Request.QueryString("ImageWidth")

If ImageURL<>"" And ImageHeight<>0 And ImageWidth<>0 Then
  'Connect to database here and save data
  Response.Write("Server side code now executing - Saving dimensions of " & ImageURL & " (" & ImageWidth & " x " & ImageHeight & ") to database")
End If
%> 

I have tested it and it basically works although it might need a little refinement as if the image hasn't finished loading then it doesn't have time to get the dimensions of the image. There might be some kind of event to watch for to show that the image has finished loading....

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close