29. januar 2004 - 10:04Der er
4 kommentarer og 1 løsning
Aflæs JPG højde og bredde i ASP
Jeg har brug for en metode (gerne en funktion) der tillader et ASP script (okay, en stump VB kode) at aflæse højde og bredde på et JPG billede.
Metoden må ikke benytte diverse specielle COM objekter da den skal være kompatibel både med Microsoft ASP og ChiliASP (Og jeg i øvrigt ikke kan registere objekter hos min webudbyder).
Højde og bredde skal bruges i layoutberegninger serverside, så koden skal være rent serverside.
AI bliver først for alvor en del af arbejdet, når teknologien integreres i den måde, vi arbejder på. At have adgang til AI betyder ikke nødvendigvis, at medarbejderne er klar til at bruge den.
javascript kan til dels - men det er jo klientside. ASP har jeg aldrig set kunnet gøre det da ASP ikke på den måde kan arbejde med billeder - normalt bruger man komponenter såsom ASPimage eller Shotgraph, så jeg tror desværre at du leder i blinde :o/
Du kan prøve dette som bruger FSO til at læser information ud fra filerne. Support for BMP, GIF, JPG og PNG.
<html> <head> <title></title> </head> <body>
<% '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: '::: ::: '::: This routine will attempt to identify any filespec passed ::: '::: as a graphic file (regardless of the extension). This will ::: '::: work with BMP, GIF, JPG and PNG 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: ::: '::: flnm => Filespec of file to read ::: '::: offset => Offset at which to start reading ::: '::: bytes => How many bytes to read ::: '::: ::: '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function GetBytes(flnm, 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(flnm) lngSize = objFTemp.Size set objFTemp = nothing
fsoForReading = 1 Set objTextStream = objFSO.OpenTextFile(flnm, 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: ::: '::: flnm => Filespec of file to read ::: '::: width => width of image ::: '::: height => height of image ::: '::: depth => color depth (in number of colors) ::: '::: strImageType=> type of image (e.g. GIF, BMP, etc.) ::: '::: ::: '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function gfxSpex(flnm, width, height, depth, strImageType)
dim strPNG dim strGIF dim strBMP dim strType strType = "" strImageType = "(unknown)"
'HER ER KODEN SOM UDSKRIVER ALLE BILLEDE FILE (JPG,GIF) FRA DEN FOLDER ASP FILEN 'LIGGER I '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: '::: TESTE KODE ::: ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Ret stien til den folder du har asp og billerne i : . = current folder Set objF = objFSO.GetFolder(Server.MapPath("."))
Set objFC = objF.Files
response.write "<table border=""0"" cellpadding=""5"">" response.write "<tr><td>Filnavn</td><td>Dato</td><td>Størrelse (bytes)</td><td>højde X bredde</td><td>Antal farver</td><td>billede</td></tr>" For Each f1 in objFC if instr(ucase(f1.Name), ".GIF") OR instr(ucase(f1.Name), ".JPG") then response.write "<tr><td>" & f1.name & "</td><td>" & f1.DateCreated & "</td><td>" & f1.Size & "</td><td>"
'Kalder function som returnere størrelsen på billet if gfxSpex(server.MapPath(f1.Name), intWidth, intHigh, intColor, strType) = true then 'Udskriv billede størrelsen response.write intHigh & " x " & intWidth
'Definer MAX hight og width maxHigh = 250 maxWidth = 300
fixedHigh = false
'Kode som udregner hight og width ud fra billede størrelese og MAS hight og width if (intWidth > maxWidth) AND (intHigh > maxHigh) then if (intWidth/maxWidth) < (intHigh/maxHigh) then fixedHigh = true end if elseif (intHigh > maxHigh) then fixedHigh = true elseif (intHigh > intWidth) then fixedHigh = true end if
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.