Avatar billede hhlundgaard Nybegynder
20. februar 2003 - 19:06 Der er 6 kommentarer og
1 løsning

Image resize med FSO

Det jeg gerne vil ha lavet er sådan at billederne bliver vist i max 200*200 og ikke altid i 200*200 som nu de ser ikke specielt godt ud nemlig.
eks: et billede på 100*500 bliver strukket rimelig meget og ser dum ud - jeg ved at eagleeye har lavet noget af det før og jeg har set på det men har ikke kunnet få lavet det.

har prøvet med at include den imgsize.asp han har lavet på et tidspunkt.
http://www.eksperten.dk/spm/239883
dette spørgsmål løste det for en bruger, men jeg kan ikke få det tilpasset min side.

<html>
<head>
<title>Produkt info</title>

</head>
<BODY BGCOLOR="#91BAEC" TEXT="#000000" LINK="#0000FF" VLINK="#800080"  bottommargin="10" leftmargin="10" topmargin="10" rightmargin="10">
  <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#91BAEC" BORDER="0" align="center">
      <%
      Set DataConn = Server.CreateObject("ADODB.Connection")
      DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("../_private/produkt.mdb")
      DataConn.Open DSN
      Set newz = Server.CreateObject("ADODB.RecordSet")
      newz.open "Select * From [Produkter] where Id = " & request("produkt") & " Order by id asc", DataConn

      Do While NOT newz.EOF
      %>
      <tr>
        <td height="25" valign="top" colspan="2" align="center"><b><%=newz("tittle")%><b></td>
      </tr>
      <tr valign="top">
        <td width="50%" height="210"><img src="vare_images/<%=newz("billede")%>" height="200" width="200"></td>
        <td valign="top" align="left">Vare nr.:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=newz("produktid")%><br><br>
          Pris:<br>
          <%
          tallet = newz("pris")
          If Instr(1,tallet,",") > 0 OR Instr(1,tallet,".") > 0 Then
          Response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & newz("pris")
          Else
          Response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & newz("pris") & ".00"
          End If
          %> kr.
        <br><br><br>
      <table width="130" cellpadding="0" cellspacing="0" bgcolor="#91BAEC" BORDER="0" align="center">
      <tr><td>
        <input type="button" value="Køb" onclick="java script:redirect('kurv.asp?action=buy&Id=<%=newz("Id")%>')" class="bot">
      </td><td align="right">
        <form action="java script:close()"><input type="submit" value="Luk vindue" class="bot">
      </td></tr></table>
        </form>
        </td>
      </tr>
      <tr>
        <td colspan="2">Beskrivelse:<br><%=newz("beskrivelse")%></td>
      </tr>

      <%
      newz.MoveNext
      Loop

      newz.close     
      set newz = nothing
      DataConn.close
      set DataConn = nothing
      %>
</BODY>
</HTML>
Avatar billede no_doubt Nybegynder
20. februar 2003 - 19:11 #1
Hvorfor ikke se på størrelserne højde, brede og sig hvis den er mindre en 200 * 200 then
Avatar billede somaliomar Praktikant
21. februar 2003 - 07:38 #2
Prøv

<%

  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)"

    gfxSpex = False

    strPNG = chr(137) & chr(80) & chr(78)
    strGIF = "GIF"
    strBMP = chr(66) & chr(77)

    strType = GetBytes(flnm, 0, 3)

    if strType = strGIF then                ' is GIF

        strImageType = "GIF"
        Width = lngConvert(GetBytes(flnm, 7, 2))
        Height = lngConvert(GetBytes(flnm, 9, 2))
        Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)
        gfxSpex = True

    elseif left(strType, 2) = strBMP then        ' is BMP

        strImageType = "BMP"
        Width = lngConvert(GetBytes(flnm, 19, 2))
        Height = lngConvert(GetBytes(flnm, 23, 2))
        Depth = 2 ^ (asc(GetBytes(flnm, 29, 1)))
        gfxSpex = True

    elseif strType = strPNG then            ' Is PNG

        strImageType = "PNG"
        Width = lngConvert2(GetBytes(flnm, 19, 2))
        Height = lngConvert2(GetBytes(flnm, 23, 2))
        Depth = getBytes(flnm, 25, 2)

        select case asc(right(Depth,1))
          case 0
              Depth = 2 ^ (asc(left(Depth, 1)))
              gfxSpex = True
          case 2
              Depth = 2 ^ (asc(left(Depth, 1)) * 3)
              gfxSpex = True
          case 3
              Depth = 2 ^ (asc(left(Depth, 1)))  '8
              gfxSpex = True
          case 4
              Depth = 2 ^ (asc(left(Depth, 1)) * 2)
              gfxSpex = True
          case 6
              Depth = 2 ^ (asc(left(Depth, 1)) * 4)
              gfxSpex = True
          case else
              Depth = -1
        end select


    else

        strBuff = GetBytes(flnm, 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
          Depth = -1

      else

          Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
          Width = lngConvert2(mid(strBuff, lngPos + 6, 2))
          Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8)
          gfxSpex = True

      end if
                 
    end if

  end function
%>



<html>
<head>
<title>Produkt info</title>

</head>
<BODY BGCOLOR="#91BAEC" TEXT="#000000" LINK="#0000FF" VLINK="#800080"  bottommargin="10" leftmargin="10" topmargin="10" rightmargin="10">
  <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#91BAEC" BORDER="0" align="center">
      <%
      Set DataConn = Server.CreateObject("ADODB.Connection")
      DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("../_private/produkt.mdb")
      DataConn.Open DSN
      Set newz = Server.CreateObject("ADODB.RecordSet")
      newz.open "Select * From [Produkter] where Id = " & request("produkt") & " Order by id asc", DataConn

      Do While NOT newz.EOF
      %>
      <tr>
        <td height="25" valign="top" colspan="2" align="center"><b><%=newz("tittle")%><b></td>
      </tr>
      <tr valign="top">
        <td width="50%" height="210">
          <%
            ImageName = server.MapPath & "/vare_images/" & newz("billede")
            gfxspex ImageName, width, height, depth, strImageType

        maxHigh = 200
        maxWidth = 200
        fixedHigh = false
 
if (width > maxWidth) AND (height > maxHigh) then
  if (width/maxWidth) < (height/maxHigh) then
    fixedHigh = true
  end if
elseif (height > maxHigh) then
  fixedHigh = true
elseif (height > intWidth) then
  fixedHigh = true
end if 
 
if fixedHigh = true then
  Response.Write "<img src=""" & "/vare_images/" & newz("billede") & """ width=""" & Int(intWidth/(intHigh/maxHigh)) & """ hight=""" & maxHigh & """>"
else
  Response.Write "<img src=""" & "/vare_images/" & newz("billede") & """ width=""" & maxWidth & """ hight=""" & Int(intHigh/(intWidth/maxWidth)) & """>"
end if
         
          %>


<img src="vare_images/<%=newz("billede")%>" height="200" width="200"></td>
        <td valign="top" align="left">Vare nr.:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=newz("produktid")%><br><br>
          Pris:<br>
          <%
          tallet = newz("pris")
          If Instr(1,tallet,",") > 0 OR Instr(1,tallet,".") > 0 Then
          Response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & newz("pris")
          Else
          Response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & newz("pris") & ".00"
          End If
          %> kr.
        <br><br><br>
      <table width="130" cellpadding="0" cellspacing="0" bgcolor="#91BAEC" BORDER="0" align="center">
      <tr><td>
        <input type="button" value="Køb" onclick="java script:redirect('kurv.asp?action=buy&Id=<%=newz("Id")%>" class="bot">
      </td><td align="right">
        <form action="java script:close()"><input type="submit" value="Luk vindue" class="bot">
      </td></tr></table>
        </form>
        </td>
      </tr>
      <tr>
        <td colspan="2">Beskrivelse:<br><%=newz("beskrivelse")%></td>
      </tr>

      <%
      newz.MoveNext
      Loop

      newz.close     
      set newz = nothing
      DataConn.close
      set DataConn = nothing
      %>
</BODY>
</HTML>
Avatar billede hhlundgaard Nybegynder
21. februar 2003 - 10:01 #3
Jeg har rettet
ImageName = server.MapPath & "/vare_images/" & newz("billede")
til:
ImageName = server.MapPath("/shop/vare_images/" & newz("billede"))

plus jeg har fjernet den overflødige <img>

Nu får jeg en overflow fejl i:
  Response.Write "<img src=" & "/shop/vare_images/" & newz("billede") & " width=""" & Int(intWidth/(intHigh/maxHigh)) & """ hight=""" & maxHigh & """>"
else
  Response.Write "<img src=" & "/shop/vare_images/" & newz("billede") & " width=" & maxWidth & " hight=" & Int(intHigh/(intWidth/maxWidth)) & ">"
end if

fejlen er :

Microsoft VBScript runtime error '800a0006'
Overflow
/shop/vareinfo.asp, line 227
så det er i udregningen af Int(intWidth/(intHigh/maxHigh)) det går galt.
Avatar billede hhlundgaard Nybegynder
21. februar 2003 - 11:18 #4
Jeg har fået tilrettet koden nu - der var nogle fejl i udregningerne, men nu kører det tak for hjælpen somaliomar svar lige så giver jeg dig nogle point.
Avatar billede somaliomar Praktikant
21. februar 2003 - 11:23 #5
OK. Hvor var fejlen helt præcist?
Avatar billede hhlundgaard Nybegynder
21. februar 2003 - 11:53 #6
Den var i response <img ...>  der havde du brugt intWidth og intHigh, disse var ikke instantieret nogen steder.
De skal instantieres i gfxspex() og da jeg gjorde det virkede det.
Avatar billede somaliomar Praktikant
21. februar 2003 - 11:54 #7
Nå ja. Det er rigtigt...
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