Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- wap
- JavaScript
- asp함수
- WML
- sql순위
- ERD
- inner join
- javascript 한글입력체크
- sql업데이트
- 이미지세로길이
- array
- FileSystemObject
- instr
- xmldom
- VARIABLE
- 이미지가로길이
- injection
- 한글입력체크
- 자바기초
- 인젝션
- 정규식
- XML
- tempDB
- SPLIT
- VarType
- sql랭킹
- MSSQL보안
- jdbc driver
- join
- update
Archives
- Today
- Total
3초기억력
ASP - LoadPicture 없이도 이미지 파일 확장자, 가로세로 길이 구하기 본문
제목 : ASP - LoadPicture 없이도 이미지 파일 확장자, 가로세로 길이 구하기
Class ImageClass
Private m_Width
Private m_Height
Private m_ImageType
Private BinFile
Private BUFFERSIZE
Private objStream
Private Sub class_initialize()
BUFFERSIZE = 65535
' Set all properties to default values
m_Width = 0
m_Height = 0
m_Depth = 0
m_ImageType = Null
Set objStream = Server.CreateObject("ADODB.Stream")
End Sub
Private Sub class_terminate()
Set objStream = Nothing
End Sub
Public Property Get Width()
Width = m_Width
End Property
Public Property Get Height()
Height = m_Height
End Property
Public Property Get ImageType()
ImageType = m_ImageType
End Property
Private Function Mult(lsb, msb)
Mult = lsb + (msb * CLng(256))
End Function
Private Function BinToAsc(ipos)
BinToAsc = AscB(MidB(BinFile, (ipos+1), 1))
End Function
Public Sub LoadFilePath(strPath)
If InStr(strPath, ":") = 0 Then
strPath = Server.MapPath(strPath)
End If
objStream.Open
objStream.LoadFromFile(strPath)
BinFile = objStream.ReadText(-1)
End Sub
Public Sub LoadBinary(BinaryFile)
BinFile = BinaryFile
End Sub
Public Sub ImageRead
If BinToAsc(0) = 137 And BinToAsc(1) = 80 And BinToAsc(2) = 78 Then
' this is a PNG file
m_ImageType = "png"
' get bit depth
Select Case BinToAsc(25)
Case 0
' greyscale
Depth = BinToAsc(24)
Case 2
' RGB encoded
Depth = BinToAsc(24) * 3
Case 3
' Palette based, 8 bpp
Depth = 8
Case 4
' greyscale with alpha
Depth = BinToAsc(24) * 2
Case 6
' RGB encoded with alpha
Depth = BinToAsc(24) * 4
Case Else
' This value is outside of it's normal range, so we'll assume that this is not a valid file
m_ImageType = Null
End Select
If not IsNull(m_ImageType) Then
' if the image is valid then
' get the width
m_Width = Mult(BinToAsc(19), BinToAsc(18))
' get the height
m_Height = Mult(BinToAsc(23), BinToAsc(22))
End If
End If
If BinToAsc(0) = 71 And BinToAsc(1) = 73 And BinToAsc(2) = 70 Then
' this is a GIF file
m_ImageType = "gif"
' get the width
m_Width = Mult(BinToAsc(6), BinToAsc(7))
' get the height
m_Height = Mult(BinToAsc(8), BinToAsc(9))
' get bit depth
m_Depth = (BinToAsc(10) And 7) + 1
End If
If BinToAsc(0) = 66 And BinToAsc(1) = 77 Then
' this is a BMP file
m_ImageType = "bmp"
' get the width
m_Width = Mult(BinToAsc(18), BinToAsc(19))
' get the height
m_Height = Mult(BinToAsc(22), BinToAsc(23))
' get bit depth
m_Depth = BinToAsc(28)
End If
If IsNull(m_ImageType) Then
' if the file is not one of the above type then
' check to see if it is a JPEG file
Dim lPos : lPos = 0
Do
' loop through looking for the byte sequence FF,D8,FF
' which marks the begining of a JPEG file
' lPos will be left at the postion of the start
'###########################요기 엔터값 없애야함
If (BinToAsc(lPos) = &HFF And BinToAsc(lPos + 1) = &HD8 And
BinToAsc(lPos + 2) = &HFF) Or (lPos >= BUFFERSIZE - 10) Then Exit Do
' move our pointer up
lPos = lPos + 1
' and continue
Loop
lPos = lPos + 2
If lPos >= BUFFERSIZE - 10 Then Exit Sub
Do
' loop through the markers until we find the one
' starting with FF,C0 which is the block containing the
' image information
Do
' loop until we find the beginning of the next marker
If BinToAsc(lPos) = &HFF And BinToAsc(lPos + 1) <> &HFF Then Exit Do
lPos = lPos + 1
If lPos >= BUFFERSIZE - 10 Then Exit Sub
Loop
' move pointer up
lPos = lPos + 1
'###########################요기 엔터값 없애야함
If (BinToAsc(lPos) >= &HC0 And BinToAsc(lPos) <= &HC3) Or
(BinToAsc(lPos) >= &HC5 And BinToAsc(lPos) <= &HC7) Or
(BinToAsc(lPos) >= &HC9 And BinToAsc(lPos) <= &HCB) Or
(BinToAsc(lPos) >= &HCD And BinToAsc(lPos) <= &HCF) Then
Exit Do
End If
' otherwise keep looking
lPos = lPos + Mult(BinToAsc(lPos + 2), BinToAsc(lPos + 1))
' check for end of buffer
If lPos >= BUFFERSIZE - 10 Then Exit Sub
Loop
' If we've gotten this far it is a JPEG and we are ready
' to grab the information.
m_ImageType = "jpg"
' get the height
m_Height = Mult(BinToAsc(lPos + 5), BinToAsc(lPos + 4))
' get the width
m_Width = Mult(BinToAsc(lPos + 7), BinToAsc(lPos + 6))
' get the color depth
m_Depth = BinToAsc(lPos + 8) * 8
End If
End Sub
End Class
사용법입니다.
Dim Image, iType, iWidth, iHeight, FileSize
Set Image = new ImageClass
With Image
.LoadFilePath("가상경로 or 물리적 경로 어떤것을 입력하던 관계없습니다.")
''''''''''''''''''''''''.LoadBinary("바이너리로 읽었을때...")
.ImageRead
iType = .ImageType
iWidth = .Width
iHeight = .Height
End With
FileSize = iWidth & "," & iHeight & "," & iType
Set Image = Nothing
내용 : LoadPicture 없이도 파일 확장자 , 가로세로 길이 구하는 클래스 - 퍼옴
퍼온 스크립트에 오타 발견, 수정함
약간 수정하여 실제 페이지에서 사용하게 변경함
test.asp
- 가로 길이가 400이 넘는 이미지는 400으로 제한, 그 이하는 그냥 그대로...
<%
'이미지 가로,세로 최고 길이
img_width = "400"
img_height = "400"
img_url = "\upload\file\test.jpg"
Set ImageFile = new ImageClass
With ImageFile
.LoadFilePath(img_url)
.ImageRead
iType = .ImageType
iWidth = .Width
iHeight = .Height
End With
ImageFileInfo = iWidth & "," & iHeight
Set ImageFile = Nothing
Filesize = Split(ImageFileInfo, ",")
OriFileWidth = CInt(Filesize(0))
OriFileHeight = CInt(Filesize(1))
%>
<img src="<%=img_url%>" width="<% If CInt(OriFileWidth)>CInt(img_width) Then response.write img_width Else response.write OriFileWidth End If %>">
- 가로 길이가 400이 넘는 이미지는 400으로 제한, 그 이하는 그냥 그대로...
<%
'이미지 가로,세로 최고 길이
img_width = "400"
img_height = "400"
img_url = "\upload\file\test.jpg"
Set ImageFile = new ImageClass
With ImageFile
.LoadFilePath(img_url)
.ImageRead
iType = .ImageType
iWidth = .Width
iHeight = .Height
End With
ImageFileInfo = iWidth & "," & iHeight
Set ImageFile = Nothing
Filesize = Split(ImageFileInfo, ",")
OriFileWidth = CInt(Filesize(0))
OriFileHeight = CInt(Filesize(1))
%>
<img src="<%=img_url%>" width="<% If CInt(OriFileWidth)>CInt(img_width) Then response.write img_width Else response.write OriFileWidth End If %>">
'플밍_ASP' 카테고리의 다른 글
| ASP - 구글 뉴스 RSS 퍼오기 (카테고리별) (0) | 2011.08.04 |
|---|---|
| ASP - URL 파일 서버경로에 저장하기 ( binary, xmlDOM ) (0) | 2011.04.27 |
| ASP - 정규식 사용하여 html 본문의 A 태그 삭제하기 (0) | 2011.04.27 |
| ASP - ServerVariables 몽땅 나타내기 (0) | 2011.04.20 |
| ASP - VarType 종류 (0) | 2011.04.20 |
Comments