Solved

image width, height and size

Posted on 2002-07-02
3
313 Views
Last Modified: 2006-11-17
Hi,

How to check the images widht, height and size in asp code?

Please help.

Thanks.
0
Comment
Question by:ht055
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 30 total points
ID: 7124057
0
 
LVL 2

Expert Comment

by:zombeen
ID: 7124296
ASPImage is anotyher very good component , used for this + a lot of other things
u shd get that one too from www.serverobjects.com
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 7126424
OR...

Sub getJPEGDimensions(ByVal filename, ByRef width, ByRef height)
     '// sets width and height to the values scooped from the JPEG referenced by filename
     '// Assumes filename supplies a full path (i.e. it has been MapPath'ed)

     Dim lBinPrefix
     Dim lLngStart
     Dim binaryData, objFS, objFile
     
     'filename = Server.MapPath(filename)
     Set objFS = Server.CreateObject("Scripting.FileSystemObject")
     
     Set objFile = objFS.OpenTextFile(filename)
     If Not objFile.AtEndOfStream Then
          binaryData = ChrB(Asc(objFile.Read(1)))
          While Not objFile.AtEndOfStream
                binaryData = binaryData & ChrB(Asc(objFile.Read(1)))
          Wend
     End If
     objFile.Close
     Set objFile = Nothing
     Set objFS = Nothing
     
     
     ' Prefix found before image dimensions          
     lBinPrefix = ChrB(&h00) & ChrB(&h11) & ChrB(&h08)
     
     ' Find the last prefix (so we don't confuse it with data)          
     lLngStart = 1
     Do
          If InStrB(lLngStart, binaryData, lBinPrefix) + 3 = 3 Then Exit Do
          lLngStart = InStrB(lLngStart, binaryData, lBinPrefix) + 3
     Loop
     ' If a prefix was found
     If Not lLngStart = 1 Then
          width = CLng("&h" & HexAt(lLngStart+2, binaryData) & HexAt(lLngStart+3, binaryData))
          height = CLng("&h" & HexAt(lLngStart, binaryData) & HexAt(lLngStart+1, binaryData))
     End If
End Sub


Function HexAt(ByRef pLngPosition, ByRef mStrBinaryData)
     If pLngPosition > LenB(mStrBinaryData) Or pLngPosition <= 0 Then Exit Function
     HexAt = Right("0" & Hex(AscB(MidB(mStrBinaryData, pLngPosition, 1))), 2)
End Function

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now