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:
  #1  
Old February 17th, 2004, 11:07 AM
GoMo's Avatar
GoMo GoMo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: London, UK
Posts: 295 GoMo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 27 m 21 sec
Reputation Power: 6
Send a message via MSN to GoMo
Question Determine the Width/Height of an Image through ASP

Hi,

Is there any way of determining an image's width or height through ASP code alone and without the need of a third-party object?

Any help would be appreciated.

Goran (GoMo)

Reply With Quote
  #2  
Old February 17th, 2004, 12:18 PM
chrismallett chrismallett is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: UK
Posts: 23 chrismallett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking dll free image properties

A 3rd party tool like ASPUpload is the best thing, but of you don't have it on your server, this is a useful piece of code I found a few years ago:

Code:
<%
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::                                                             :::
  ':::  This routine will attempt to identify any filespec passed  :::
  ':::  as a graphic file (regardless of the extension). This will :::
  ':::  work with GIF or JPG files.                     	   :::
  ':::                                                             :::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::          Based on ideas presented by David Crowell          :::
  ':::                   (credit where due)                        :::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  '::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  '::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  '::: blah blah     Copyright *c* MM,  Mike Shaffer     blah blah :::
  '::: blah blah      ALL RIGHTS RESERVED WORLDWIDE      blah blah :::
  '::: blah blah  Permission is granted to use this code blah blah :::
  '::: blah blah   in your projects, as long as this     blah blah :::
  '::: blah blah      copyright notice is included       blah blah :::
  '::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  '::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::                                                             :::
  ':::  This function gets a specified number of bytes from any    :::
  ':::  file, starting at the offset (base 1)                      :::
  ':::                                                             :::
  ':::  Passed:                                                    :::
  ':::       sFileName        => Filespec of file to read          :::
  ':::       offset      => Offset at which to start reading       :::
  ':::       bytes       => How many bytes to read                 :::
  ':::                                                             :::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  function GetBytes(sFileName, offset, bytes)

     Dim objFSO
     Dim objFTemp
     Dim objTextStream
     Dim lngSize

     on error resume next

     Set objFSO = CreateObject("Scripting.FileSystemObject")
     
     ' First, we get the filesize
     Set objFTemp = objFSO.GetFile(sFileName)
     lngSize = objFTemp.Size
     set objFTemp = nothing

     fsoForReading = 1
     Set objTextStream = objFSO.OpenTextFile(sFileName, fsoForReading)

     if offset > 0 then
        strBuff = objTextStream.Read(offset - 1)
     end if

     if bytes = -1 then		' Get All!

        GetBytes = objTextStream.Read(lngSize)  'ReadAll

     else

        GetBytes = objTextStream.Read(bytes)

     end if
    
     objTextStream.Close
     set objTextStream = nothing
     set objFSO = nothing

  end function


  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::                                                             :::
  ':::  Functions to convert two bytes to a numeric value (long)   :::
  ':::  (both little-endian and big-endian)                        :::
  ':::                                                             :::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  function lngConvert(strTemp)
     lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))
  end function

  function lngConvert2(strTemp)
     lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256)))
  end function

  
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ':::                                                             :::
  ':::  This function does most of the real work. It will attempt  :::
  ':::  to read any file, regardless of the extension, and will    :::
  ':::  identify if it is a graphical image.                       :::
  ':::                                                             :::
  ':::  Passed:                                                    :::
  ':::       sFileName        => Filespec of file to read          :::
  ':::       width       => width of image                         :::
  ':::       height      => height of image                        :::
  ':::                                                             :::
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  function gfxSpex(sFileName, width, height)
  	'get the width and height of the passed file
  	'can only be a GIF or JPG

     dim strGIF
     dim strType
     strType = ""
     strImageType = "(unknown)"

     gfxSpex = False
     
     strGIF = "GIF"

     strType = GetBytes(sFileName, 0, 3)

     if strType = strGIF then				' is GIF

        strImageType = "GIF"
        Width = lngConvert(GetBytes(sFileName, 7, 2))
        Height = lngConvert(GetBytes(sFileName, 9, 2))
        gfxSpex = True

     else

        strBuff = GetBytes(sFileName, 0, -1)		' Get all bytes from file
        lngSize = len(strBuff)
        flgFound = 0

        strTarget = chr(255) & chr(216) & chr(255)
        flgFound = instr(strBuff, strTarget)

        if flgFound = 0 then
           exit function
        end if

        strImageType = "JPG"
        lngPos = flgFound + 2
        ExitLoop = false

        do while ExitLoop = False and lngPos < lngSize

           do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize
              lngPos = lngPos + 1
           loop

           if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
              lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
              lngPos = lngPos + lngMarkerSize  + 1
           else
              ExitLoop = True
           end if

       loop

       if ExitLoop = False then

          Width = -1
          Height = -1

       else

          Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
          Width = lngConvert2(mid(strBuff, lngPos + 6, 2))
          gfxSpex = True

       end if
                   
     end if

  end function

%>

Reply With Quote
  #3  
Old February 17th, 2004, 01:48 PM
GoMo's Avatar
GoMo GoMo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: London, UK
Posts: 295 GoMo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 27 m 21 sec
Reputation Power: 6
Send a message via MSN to GoMo
thanks for your reply but i'm still having a little trouble trying to implement this. i've experimented with the functions above and i can't see how you'll obtain the width and height when you have to provide them as parameters. i'm still a little rusty on ASP as i've converted from PHP and Java.

could you also provide some code that would obtain the width of a file called 'image.gif' found in the same directory.

thanks.

Reply With Quote
  #4  
Old February 18th, 2004, 07:08 AM
chrismallett chrismallett is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: UK
Posts: 23 chrismallett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This should work:

Code:
'get the image path
sPath = "image.gif"

If gfxSpex(Server.Mappath(sPath), w, h) then
	'if a valid image (GIF or JPG) get dimensions
	response.write "Width = " & w
	response.write "<br>Height = " & h
End If

Reply With Quote
  #5  
Old February 18th, 2004, 08:26 AM
GoMo's Avatar
GoMo GoMo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: London, UK
Posts: 295 GoMo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 27 m 21 sec
Reputation Power: 6
Send a message via MSN to GoMo
that works a treat, but for some reason it only works for gif images and not jpg's. but i'll only need it for gif's anyway so it'll do fine.

i didn't realise that the primitive data types were passed 'by reference', i always thought that by default it was passed 'by value'. well thats the case for java anyway.

thanks chris

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Determine the Width/Height of an Image through ASP


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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT