Community discussion forum

Retrieving Remote Image Properties in ASP

This is a comment thread discussing Retrieving Remote Image Properties in ASP
  • 9 years ago

    This thread is for discussions of Retrieving Remote Image Properties in ASP.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 years ago

    Excellent code -- i'd been struggling with the original code and had a problem opening and reading the image files -- i swapped in this code and my routines ran the first time.


    My travel pages contain hundreds of images and i need a quick way to add new images and display them across many different pages.   so i wrote a routine that lets the user decide whether to display in thumbnail, caption only, or full size.  until now, i didnt have an easy way of knowing the format, so i had to encode whether the image was horizontal or vertical -- now it works as it should, and will allow me to scale images in all fomats, too.  


    to see a sample of this in action:


    http://cascoly.com/trav/turkey/Konya.asp


    thanks
    steve

  • 5 years ago

    I'm struggling with the original code, too.
    Especially the line:


    - obj.open "GET", URL, False


    returns the error: invalid procedure call.


    Could you please print your changes you made to make the code run?


    Thanx a lot,
    Flummi

  • 5 years ago

    I have an ASP based content control utility with around 30 editors each usnig the system.  We have a flash application that only takes in non-progressive images dynamically.  I need to ensure that when an editor uploads a new image to our server it's in the non-progressive format.  I looked over your code brriefly and noticed that you were checking bytes from the file to gather information about it.  What byte information could I grab to check to see if the file's progressive or not?

  • 5 years ago

    I used this in its original form, but this is a better version.  Has anyone ever converted this the Javascript?

  • 5 years ago

    This is great! Ive been looking for something like this for weeks! Thanks
    But is there a way to get the size of the file? Purhaps in KBs? Thanks!

  • 5 years ago

    Hi Spanno;
    - - I'm dealing with this same issue. I have developed a self-administrated flash photo gallery which accepts user-uploaded jpgs via an ASP server-side upload component (saFileUp). Unfortunately, some people are uploading progressive jpgs, which then do not show up in the flash interface. I DO have a COM object from SoftArtisans (ImgWriter), which can re-save JPG's in non-progressive format. The problem is, I have no way of determining (reading) the progressive property. Thus, I would have to indiscriminately re-save all jpgs as non-progressive, without knowing whether they were progressive to begin with. This results in the re-compression of existing jpgs and the consequent loss of image quality. Plus, the imgWriter's compression algorithm is not very good, and it often results in a larger file size for a poorer quality image. I was hoping someone might know of how I can read the progressive property at upload time and then I can either reject the file or auto-re-save it with the progessive property set to false.


    Let me know if you figured this one out spanno! I will also re-post here if I can solve this...

  • 5 years ago

    How to use this script ?
    I'm newbie in ASP.
    Can anyone tell me how to display the output of the width and height of the images?
    Let say I have a jpg file, picture.jpg, and I store it in root directory of my web folder.
    What command must I add to display the width and height of picture.jpg ?
    Response.Write blablabla bla?

  • 5 years ago

    Hey y'all, I've just astounded myself by being able to use this peice o' code, so I thought I'd share it with you.
    The code below calls the function and print the results.


    Salmo xxx


    <%
    dim theURL, theWidth, theHeight, theDepth, theFlType, blnImageStuff
    theURL = "http://www.notongues.com/flyer.jpg"
    theWidth = 0
    theHeight = 0
    theDepth = 0
    theFlType = ""


    blnImageStuff = getSize(theURL, theWidth, theHeight, theDepth, theFlType)


    if blnImageStuff then
       response.Write(theWidth & "<br>")
       response.Write(theHeight & "<br>")
       response.Write(theDepth & "<br>")
       response.Write(theFlType & "<br>")
    else
       response.Write("Hmm, that didn't seem to work...")
    end if
    %>

  • 5 years ago

    Thanks for the code
    I've been waiting it for so long. It takes 1 month to get the reply.


    Can I change the URL with the path such as /image ??
    I find it becomes very slow for the script to be run if I use the complete URL like http://...
    I place the image file in one folder inside the folder where I put the script. And probably it will be faster if I change URL with the path.
    If I can change it, what is the command?

  • 5 years ago

    I think the script uses the HTTP headers to acertain certain stuff, which would be information which would have to be come by another way with a file sitting on your server, so in short, no. It's well beyond me powers. soz


    salmo xxx

  • 5 years ago

    Hi,


    I needed a way to find width and height of an image and came up with this script. I use loadpicture vbscript function to get image dimensions. The OS will return dimensions in metric scale (cm/1000). Windows screen res. is 96 dots per inch. 1 inch is 2.54 cm.
    2.54/96*1000 = 26.4583


    I know that the script above scales images but if you just need image dimensions this works fine. You can also get the type, handle, and palette of the image. Props are on msdn: click here


    Code:

    <%
    dim iWidth, iHeight, iType
    sub ImgDimension(img)
       dim myImg, fs
       Set fs= CreateObject("Scripting.FileSystemObject")
       if not fs.fileExists(img) then exit sub
       set myImg = loadpicture(img)
       iWidth = round(myImg.width / 26.4583)
       iHeight = round(myImg.height / 26.4583)
       iType = myImg.Type
       select case iType
       case 0
           iType = "None"
       case 1
           iType = "Bitmap"
       case 2
           iType = "Metafile"
       case 3
           iType = "Icon"
       case 4
           iType = "Win32-enhanced metafile"
       end select
       set myImg = nothing
    end sub


    ' so if you whant to test it in asp just give the path to your image
    ImgDimension(Server.MapPath("../.") & "\images\uc.gif")


    response.write("Dimensions: " & iWidth & " x " & iHeight & "<br>")
    response.write("Image Type: " & iType & "<br>")
    %>




  • 5 years ago

    I created this code to scale an image to fit in a fixed space.  Does anyone know a shorter script that will work?


    <%'----routine to scale image if it is too big------
    maxht = 50 'max height of image
    maxwt = 130 'max width of image


    If theHeight > maxht AND theWidth > maxwt then
    imgfactor = theHeight / maxht
    imght = int(theHeight / imgfactor)
    imgwt = int(theWidth / imgfactor)
    End If


    If theWidth > maxwt AND theHeight < maxwt then
    imgfactor = theWidth / maxwt
    imght = int(imght / imgfactor)
    imgwt = int(theWidth / imgfactor)
    End If


    If theHeight > maxwt AND theWidth < maxwt then
    imgfactor = theHeight / maxht
    imght = int(theHeight / imgfactor)
    imgwt = int(imgwt / imgfactor)
    End If
    %>
    <img src="<%=theURL%>" height="<%=imght%>" width="<%=imgwt%>" />

  • 5 years ago

    Geez, I wasted hours and hours trying to find a script that does what you have posted here. I need something for which I could get the dimensions of one specific image (filename passed to the script by a querystring) and then use querystrings and redirects to enter the dimensions into Access database fields!!!!!!!!


    Thank you, thank you!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 5 years ago
  • 4 years ago

    I used the "getsize" script on a shared web server, that I believe had Windows 2000 server on it, and it worked great.  I then moved to a dedicated server that had Windows 2003 server on it and suddenly the script didn't work.  No errors occured, it's just that I was not able to assertain the image properties anymore.  Basically it can't identify the file type for some reason, and therefore can't return the image width and height.  Would you know any reason why the getsize script would not work the same on a Windows 2003 server?

  • 4 years ago

    Have you had any luck in getting this script to work?


    I am trying to fit this script into an asp.net page, and I am not able to make it function either.  I was wondering if you were able to get it too work?


  • 4 years ago

    Good function! Thank you for share!

  • 4 years ago

    Quote:
    [1]Posted by aprida on 24 Jun 2003 02:25 AM[/1]
    Thanks for the code
    I've been waiting it for so long. It takes 1 month to get the reply.


    Can I change the URL with the path such as /image ??
    I find it becomes very slow for the script to be run if I use the complete URL like http://...
    I place the image file in one folder inside the folder where I put the script. And probably it will be faster if I change URL with the path.
    If I can change it, what is the command?




    yes,it can deal with local image file, use it like this:
    aa = getSize( Server.MapPath("emblem/chidori.gif"), width, height, depth, flType )

  • 4 years ago

    It works on our local test server but it is not working on our web server
    and it's show the error msxml3.dll error '800c0005'.
    if any body have any solution for this then plz mail me.

  • 4 years ago

    Thanks, I have been trying to do this from many days. This has help me a lot. Once again thank you very much.

  • 3 years ago

    Singh,


    I know this post is almost 6 months old, but as your listing is first in Google, I thought I would respond with what solved this problem for me.  I believe my issue was some kind of DNS / Firewall issue.  I was using http://www.mydomain.com/thefileforxmlparsertoget.asp.  However, when I logged into my server and tried to get to that page, I couldn't.  I could get to it from my own machine, but not from the server.  It was not until I used my internal 192.168 address (private internal address) of the web server that I actually got my script to work.  So, instead of using my domain, I used http://192.168.1.1/thefileforthexmlparsertoget.asp.  I hope that helps.  If you think about it, it makes sense.  The XML script is running server side in my script, so therefore, the SERVER is actually making the call, not the client.


    I doubt that helps any, but it sure solved my problem after about an hour or two of digging.

  • 3 years ago

    Dear stoneman,


    Thanks a lot.


    Regards,
    Ram Janm Singh
    Chetu Inc.
    Ph: +91 120-3946734 - outside US
    Ph: +1 (305) 402 6724 - within US
    Fax: +1 305 832 5987
    Mb: +91 9868 567 152
    For more information, please visit: http://www.chetu.com

  • 3 years ago

    Been searching on this for days.


    I am confirming that is has something to do with a firewall.


    I have access to 4 servers.  2 running Windows 2000 SBS (small business server) with ISA firewall - 2 nics.     2 servers with regular 2000 server.


    The 2 with 2k server run great.  No problems.
    The 2 with SBS both have problems giving the c0005 error.
    If you run your ASP page to do your request within the server, then it works.  Not externally though.  The error is always at the .send command.


    Traxxas Revo T-Maxx Parts TMaxx Store

  • 3 years ago

    I adapted some code I used so it used the same style and variable names as your code.
    The idea of this code is to make sure the image will fit within a max rectangle and keep the image's aspect ratio the same. Also it prevents divide by zero errors if the image dimensions are unknown and rounds the new height and width to the nearest pixel instead of the next smaller pixel.
    The code can be made to scale up smaller images to fit the max ractangle as well by replacing the following line with the one just below it. Great for thumbnail images!
    If theWidth>=1 and theHeight >=1 and (theWidth>maxwt or theHeight>maxht) then
    If theWidth>=1 and theHeight >=1 then



    <%'----routine to scale image if it is too big------
    maxht = 50 'max height of image
    maxwt = 130 'max width of image
    maxaspect=maxht/maxwt 'aspect ratio of max rectangle


    If theWidth>=1 and theHeight >=1 and (theWidth>maxwt or theHeight>maxht) then
    theAspect=theHeight/theWidth
    If theAspect>maxaspect then
    'Image has taller aspect ratio than max rectangle
    imght=maxht
    imgwt=int(maxht/theAspect+.5)
    Else
    'Image has wider aspect ratio than max rectangle
    imght=int(maxwt*theAspect+.5)
    imgwt=maxwt
    End If
    Else
    'Image has either no width or no height or fits within max rectangle
    imght=theHeight
    imgwt=theWidth
    End If
    %>
    <img src="<%=theURL%>" height="<%=imght%>" width="<%=imgwt%>" />

  • 3 years ago

    Howzit


    i'm new to asp, i tried to apply the code, now my pictures do not display at all?


    do u need a component to run this code or issit asp.net?


    thanks

  • 3 years ago

    Don't forget to set theHeight, theWidth, and theURL before running this code.
    I styled it based on the first post. Since it was assumed the variables were set before running this code, I did the same. If you are displaying an image that you don't know the height and width ahead of time you can use a component to find out what dimensions are. ImageSize component available at http://www.serverobjects.com/products.htm is commonly used and it's free!


    If you neglected to set the height and width of the original image, my code will generate something like the following...


    <img src="theImage.jpg" height="" width="" />


    Internet Explorer displays a 0px X 0px graphic which can't be seen.



    Better yet try this fucntion...
    <%'----Function to scale an image to fit------
    Function ImageBound(theURL,maxht,maxwt,scaleup)
       'maxht - max height of image
       'maxwt - max width of image
       'scaleup - False only scales down large images. True also scales up small images.
       '        Note: When set to false the function only scales down images that are oversized.
       '            True resizes all images to fit within the available rectangle with aspect retained.
       'theURL - The relative URL of the image.
       'You must have the ImageSize component installed for this to work.
       'http://www.serverobjects.com/products.htm
       set Img = Server.CreateObject("ImgSize.Check")
       Img.FileName = Server.MapPath(theURL)
       if Img.Error <> "" then
           Response.Write "An error occurred in processing this image.<br>"
           Response.Write "The error was: <b>" & Img.Error & "</b>"
       else
           theHeight=Img.Height
           theWidth=Img.Width
           maxaspect=maxht/maxwt 'aspect ratio of max rectangle
           If theWidth>=1 and theHeight >=1 and ((theWidth>maxwt or theHeight>maxht) or scaleup) then
               theAspect=theHeight/theWidth
               If theAspect>maxaspect then
                   'Image has taller aspect ratio than max rectangle
                   imght=maxht
                   imgwt=int(maxht/theAspect+.5)
               Else
                   'Image has wider aspect ratio than max rectangle
                   imght=int(maxwt*theAspect+.5)
                   imgwt=maxwt
               End If
           Else
               'Image has either no width or no height or fits within max rectangle
               imght=theHeight
               imgwt=theWidth
           End If
       end if
       ImageBound= "<img src=""" & theURL & """ height=""" & imght & """ width=""" & imgwt & """ />"
       set Img = nothing
    End Function


    response.write ImageBound("/images/image.jpg",50,75,True)
    response.write ImageBound("/images/image.jpg",50,75,False)
    %>

  • 3 years ago

    Hi,


    I wrote a code to save on my site a file from an URL in ASP. You can save an image (jpg,gif,...) or another binary file.


    The code is here : http://www.eromandie.com/codesource/asp/savefilefrom_url.asp


    Regards


    Youk88

Post a reply

Enter your message below

Sign in or Join us (it's free).