Avatar billede c-sharp Nybegynder
27. maj 2003 - 07:56 Der er 8 kommentarer og
1 løsning

Kan man finde størrelsen på et billede

Jeg har brug for at finde ud af om et billede står på højkant eller om det ligger normalt. Kan jeg på nogen måde finde ud længde eller breden på billedet?
Avatar billede dk_akj Nybegynder
27. maj 2003 - 08:03 #1
Hvis du har adgang til aspimage kan du bruge egenskaberne maxx og maxy til at finde størrelsen.

//akj
Avatar billede cesil Nybegynder
27. maj 2003 - 08:26 #2
du kan gøre også gøre det uden.

<%
strGrafik = "images/mitbillede.gif"
Size = ReadImg(strGrafik)
Response.Write "<p>Størrelsen på &quot;<b>/" & strGrafik & "</b>&quot; er: " & Size(0) & "x" & Size(1) & "<br>"
Response.Write "<p><img src=/" & strGrafik & "></p>"
%>
</body></html>
<%
Dim Size

Function AscAt(s, n)
    AscAt = Asc(Mid(s, n, 1))
End Function

Function HexAt(s, n)
    Dim lsH
    lsH = Hex(AscAt(s, n))
    If Len(lsH) <> 2 Then lsH = "0" & lsH
    HexAt = lsH
End Function

Function isJPG(filen)
    If inStr(uCase(filen), ".JPG") <> 0 Or inStr(uCase(filen), ".JPEG") <> 0 Then
        isJPG = true
    Else
        isJPG = false
    End If
End Function

Function isPNG(filen)
    If inStr(uCase(filen), ".PNG") <> 0 Then
        isPNG = true
    Else
        isPNG = false
    End If
End Function

Function isGIF(filen)
    If inStr(uCase(filen), ".GIF") <> 0 Then
        isGIF = true
    Else
        isGIF = false
    End If
End Function

Function isBMP(filen)
    If inStr(uCase(filen), ".BMP") <> 0 Then
        isBMP = true
    Else
        isBMP = false
    End If
End Function

Function isWMF(filen)
    If inStr(uCase(filen), ".WMF") <> 0 Then
        isWMF = true
    Else
        isWMF = false
    End If
End Function

Function isWebImg(f)
    If isGIF(f) Or isJPG(f) Or isPNG(f) Or isBMP(f) Or isWMF(f) Then
        isWebImg = true
    Else
        isWebImg = true
    End If
End Function

Function ReadImg(filen)
    If isGIF(filen) Then
        ReadImg = ReadGIF(filen)
    Else
        If isJPG(filen) Then
            ReadImg = ReadJPG(filen)
        Else
            If isPNG(filen) Then
                ReadImg = ReadPNG(filen)
            Else
                If isBMP(filen) Then
                    ReadImg = ReadPNG(filen)
                Else
                    If isWMF(filen) Then
                        ReadImg = ReadWMF(filen)
                    Else
                        ReadImg = Array(0,0)
                    End If
                End If
            End If
        End If
    End If
End Function

Sub Rep(s)
    Response.Write s & "<BR>"
End Sub

Function ReadJPG(filen)
    Dim fso, ts, s, HW, ns, n, ok
    HW = Array("","")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
    ts.Skip(2)
    ns = ts.Read(2)
    Do While Not (ns = "ÿÀ" Or ns = "ÿÂ")
        ns = ts.Read(2)
        n = HexToDec(HexAt(ns,1) & HexAt(ns,2))
        n = n - 2
        ts.Skip(n)
        ns = ts.Read(2)
    Loop
    ts.Skip(3)
    s = ts.Read(4)
    HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
    HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2))
    ts.Close
    Set ts = Nothing
    ReadJPG = HW
End Function

Function ReadPNG(filen)
    Dim fso, ts, s, HW, nbytes
    HW = Array("","")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
    s = Right(ts.Read(24), 8)
    HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
    HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8))
    ts.Close
    ReadPNG = HW
End Function

Function ReadGIF(filen)
    Dim fso, ts, s, HW, nbytes
    HW = Array("","")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
    ts.Skip(6)
    s = ts.Read(4)
    HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
    HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
    ts.Close
    ReadGIF = HW
End Function

Function ReadWMF(filen)
    Dim fso, ts, s, HW, nbytes
    HW = Array("","")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
    s = Right(ts.Read(14), 4)
    HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
    HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
    ts.Close
    ReadWMF = HW
End Function

Function ReadBMP(filen)
    Dim fso, ts, s, HW, nbytes
    HW = Array("","")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
    s = Right(ts.Read(24), 8)
    HW(0) = HexToDec(HexAt(s,4) & HexAt(s,3))
    HW(1) = HexToDec(HexAt(s,8) & HexAt(s,7))
    ts.Close
    ReadBMP = HW
End Function

Function isDigit(c)
    If inStr("0123456789", c) <> 0 Then
        isDigit = true
    Else
        isDigit = false
    End If
End Function

Function isHex(c)
    If inStr("0123456789ABCDEFabcdef", c) <> 0 Then
        isHex = true
    Else
        ishex = false
    End If
End Function

Function HexToDec(cadhex)
    Dim n, i, ch, decimal
    decimal = 0
    n = Len(cadhex)
    For i=1 To n
        ch = Mid(cadhex, i, 1)
        If isHex(ch) Then
            decimal = decimal * 16
            If isDigit(ch) Then
                decimal = decimal + ch
            Else
                decimal = decimal + Asc(uCase(ch)) - Asc("A") + 10
            End If
        Else
            HexToDec = -1
        End If
    Next
    HexToDec = decimal
End Function
%>
Avatar billede donwang Nybegynder
27. maj 2003 - 08:29 #3
Skift dog til PHP...! I php ser det sådan ud:
<?php
$size = getimagesize ("billed.jpg");
print("{$size[3]}");
?>
Avatar billede dk_akj Nybegynder
27. maj 2003 - 08:31 #4
... og i asp slipper man for at skrive $ hele tiden ;-)

//akj
Avatar billede c-sharp Nybegynder
27. maj 2003 - 08:31 #5
dk_akj>> har du et hurtigt eksempel på hvordan jeg bruger aspimage til dette
Avatar billede oasen Nybegynder
27. maj 2003 - 08:54 #6
Avatar billede dk_akj Nybegynder
27. maj 2003 - 08:59 #7
Set Image = Server.CreateObject("AspImage.Image")
Image.LoadImage "d:\web\billede.jpg"
bredde = image.maxx
hoejde = image.maxy

set image = nothing.

Hvis du skal checke på gif's skal du bruge cesil's svar da aspimage ikke understøtter gif. (vist nok pga. nogle rettigheder til formatet.)

//akj
Avatar billede c-sharp Nybegynder
27. maj 2003 - 09:37 #8
Jeg takker!!
Avatar billede dk_akj Nybegynder
27. maj 2003 - 09:38 #9
selvtak.

//akj
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester