Avatar billede powerade Nybegynder
07. september 2007 - 18:37 Der er 1 kommentar og
1 løsning

Resize image i javascript/html/asp fotoalbum

Jeg har "stjålet" et asp/javascript/html fotoalbum fra nettet.

Det fungerer som de fleste andre albums, ved at PhotoAlbum.asp finder alle billeder i subdir's, og et popup-vindue med kilde fra ShowPicture.asp viser det billede man har klikket på.

Mit problem består nu i at når jeg klikker på et billede og det åbnes i et nyt vindue, er billederne ofte i så stor opløsning at de ikke kan være i vinduet, og at de ikke auto resizes af IE.

Kan nogen hjælpe med lidt rettelser til koden så den resizer billedet til at passe i vinduet?

Pft. - kode til de to filer herunder:
PhotoAlbum.asp
<%

' PhotoAlbum

Dim CurFile, PopFileShowSub, ShowPic, PictureNo
Dim strPathInfo, strPhysicalPath


Dim intTotPics, intPicsPerRow, intPicsPerPage, intTotPages, intPage, strPicArray()
intPicsPerRow  = 4
intPicsPerPage = 8

intPage = CInt(Request.QueryString("Page"))
If intPage = 0 Then
    intPage = 1
End If

CurFile = "PhotoAlbum.asp"
PopFile = "ShowPicture.asp"
%>
<link rel="stylesheet" type="text/css" href="style.css">
<style>

a:link {
    color: #172166;
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
}

a:visited {
    color: #172166;
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
}

a:active {
    color: #FF0000;
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
}

a:hover {
    color: #FF0000;
    text-decoration: underline;
    font-size: 12px;
    font-weight: bold;
}

</style>
<script language="JavaScript">
<!--
function jumppage(sel)
{
  var i = sel.selectedIndex
  self.location.href = sel.options[i].value
}
// -->
</script>
<script language="JavaScript">
<!-- hide from JavaScript-challenged browsers
function openGalleryWindow(url) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 800, yMax=600;
    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
    var xOffset = 100, yOffset = 100;

    popupWin =

window.open(url,'new_page','width=700,height=535,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',scrollbars=yes,toolbars=no,menubar=no,resizable=yes')
}
// done hiding -->
</script>

<center>

<%
ShowSub = request("ShowSub")
ShowPic = request("ShowPic")
strPathInfo = Request.ServerVariables("PATH_INFO")
strPhysicalPath = Server.MapPath(strPathInfo)

if ShowSub <= " " then
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile(strPhysicalPath)
  Set objFolder = objFile.ParentFolder
  Set objFolderContents = objFolder.Files
  For each Folder in objFolder.SubFolders
    ShowSub = Folder.Name
    Exit For
  Next
  Set objFSO = Nothing
end if
%>

<%
If ShowPic > " " then
  ShowPic = Replace(ShowPic, " ", "%20")
  Response.Write "<a href='java script:history.go(-1)'><img src='" & ShowPic & "'><BR><BR><font face=""verdana"" size=""1""><b>G&aring; tilbage</b></a>"
Else
%>
  <table border="0" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#000000" width="100%" id="AutoNumber2">
  <tr>
  <%
  strPhysicalPath = Server.MapPath("./" & ShowSub)
  If ShowSub > " " then
    ShowSub = Replace(ShowSub, " ", "%20")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(strPhysicalPath)
    Set objFolderContents = objFolder.Files

    'Get the number of pictures in the subdirectory
    intTotPics = 0
    For Each objFileItem in objFolderContents
        If Ucase(Right(objFileItem.Name,4))=".GIF" OR Ucase(Right(objFileItem.Name,4))=".JPG" OR Ucase(Right(objFileItem.Name,5))=".JPEG" THEN
            intTotPics = intTotPics + 1
        End if
    Next

    'Get the total number of pages in the subdirectory
    If (intTotPics/intPicsPerPage) = (int(intTotPics/intPicsPerPage)) Then
        intTotPages = int(intTotPics/intPicsPerPage)
    Else
        intTotPages = int(intTotPics/intPicsPerPage)+1
    End If
    Redim strPicArray(2,intTotPics)

    'Store picture file names in an array
    x = 0
    For Each objFileItem in objFolderContents
        If Ucase(Right(objFileItem.Name,4))=".GIF" OR Ucase(Right(objFileItem.Name,4))=".JPG" OR Ucase(Right(objFileItem.Name,5))=".JPEG" THEN
            strPicArray(0,x) = objFileItem.Name
            strPicArray(1,x) = Cstr(int(x/intPicsPerPage)+1)
            x = x + 1
        End if
    Next

    For x = 0 to UBound(strPicArray,2)-1
    If CInt(strPicArray(1,x)) = intPage Then
      ShowPic = Replace(strPicArray(0,x), " ", "%20")
      Response.write "<td align='center' width='25%'><a href=""java script:openGalleryWindow('" & PopFile & "?ShowPic=" & ShowSub & "/" & ShowPic & "')"""
      Response.write "<br>"
      Response.Write("<img src='" & ShowSub & "/" & strPicArray(0,x) & "' width=150 border='0'> ")
      'Response.Write("<br><font color=""" & strBaseFontColor & """><b>" & Mid(strPicArray(0,x),1,Len(strPicArray(0,x))-4) & "</b></font>")
      Response.write "</a></td>" & vbcrlf

      PictureNo = PictureNo + 1
      If PictureNo=intPicsPerRow Then
          Response.write "</tr><tr>"
          PictureNo = 0
      End if
    End If
    Next


    'Determine if there are multiple pages and if so, display page numbers.
    If intTotPages > 1 Then
        Response.Write "<td colspan='" & intPicsPerRow & "' align='center'><font face='Verdana,Arial' size='1'>Side:&nbsp;&nbsp;&nbsp;"
        For x = 1 to intTotPages
            If x = intPage Then
                Response.Write "</font><font face='Arial' size='2'>" & x & "</font><font face='Arial' size='1'>&nbsp;&nbsp;&nbsp;&nbsp;"
            Else
                Response.Write "<a href='PhotoAlbum.asp?Page=" & x & "&ShowSub=" & ShowSub & "'>" & x & "</a>&nbsp;&nbsp;&nbsp;&nbsp;"
            End If
        Next
        Response.Write "</font></td>"
        Response.Write "</tr><tr><td>&nbsp;</td></tr><tr>"
    End If

    Set objFSO = Nothing
  End if
  %>
  </tr>
  </table>
<%
End if
%>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" width="100%" id="AutoNumber1">
<tr>

<td align="center" width="25%">
  <form action=<%=PopFile%> method="POST" id=form1 name=form1>
  <font face="<%= strDefaultFontFace %>" size="<% =strFooterFontSize %>" color="<% =strBaseFontColor %>"><b>Foto album:</b>
  <select name="go" onChange="jumppage(this);" size=1>
  <%

  strPathInfo = Request.ServerVariables("PATH_INFO")
  strPhysicalPath = Server.MapPath(strPathInfo)

  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile(strPhysicalPath)
  Set objFolder = objFile.ParentFolder
  Set objFolderContents = objFolder.Files
  For each Folder in objFolder.SubFolders
      If Left(Folder.Name,1)<>"_" Then
          Response.write "<option "
          If ShowSub=Folder.Name Then
              Response.Write "selected "
          End if
          Response.Write"value='" & CurFile & "?ShowSub="
          Response.Write(Replace(Folder.Name, " ", "%20"))
          response.write "'>"
          Response.Write(Folder.Name & "</option>")
'          If ShowSub <= " " Then
'            ShowSub = Folder.Name
'        End if
      End if
  Next
  Set objFSO = Nothing
  %>
  </select></h3>
  </form>
  </td>
</tr>
</table>

</center>
</html>

ShowPicture.asp
<%
' ASP Picture Album

Dim CurFile, ShowSub, ShowPic, PictureNo
Dim strPathInfo, strPhysicalPath

CurFile = "ShowPicture.asp"
%>

<html><head>
<title></title>
<script language="JavaScript">
<!--
function jumppage(sel)
{
  var i = sel.selectedIndex
  self.location.href = sel.options[i].value
}
// -->
</script>
</head><body>

<center>
<%
'ShowSub = request("ShowSub")
ShowPic = request("ShowPic")
'strPathInfo = Request.ServerVariables("PATH_INFO")
'strPhysicalPath = Server.MapPath(strPathInfo)

'Set objFSO = CreateObject("Scripting.FileSystemObject")


If ShowPic > " " then
  ShowPic = Replace(ShowPic, " ", "%20")
  Response.Write "<a href='java script:window.close()'><img src='" & ShowPic & "'></a>"
Else
  Response.Write "Error...No picture file"
End if
%>
</center>
</html>
Avatar billede powerade Nybegynder
08. september 2007 - 11:54 #1
Hvis nogen har et forslag til et alternativt fotoalbum, med ovenstående funktionalitet, samt resize af billeder til at passe i vinduet, er sådanne forslag også velkomne. Der gives dog først og fremmest point for at svare på det oprindelige spørgsmål/problem.
Avatar billede powerade Nybegynder
08. september 2007 - 14:21 #2
Jeg endte med at gøre det mest simple - editere img html tagget og sætte height=90%.
Nogen gange skal man vælge den nemmese udvej åbenbart. ;o)
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
Vi tilbyder markedets bedste kurser inden for webudvikling

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