I created a gallery in ASP.NET by which all you need to do is put the image in a folder (and use sub folders as categories) and it will pick it up & generate the thumbnail for you.
This gets the files and puts them in a Repeater control:
Code:
<%@ Page Language="VB" Debug="True" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Dim IsIE As Boolean
Sub Page_Load
Dim dirInfo as New DirectoryInfo(Server.MapPath("/images/gallery/" & Request.QueryString("category") & "/"))
repGallery.DataSource = dirInfo.GetFiles("*.jpg")
repGallery.DataBind()
If Request.Browser.Browser.ToString() = "IE" Then
IsIE = True
Else
IsIE = False
End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
div#Images {
}
div.Thumb {
border: 1px solid blue;
float: left;
margin: 5px;
padding: 3px;
}
</style>
</head>
<body>
<form runat="server">
<div id="Body">
<h1><%= Request.QueryString("category") %></h1>
<p class="Content">Click and image thumbnail to enlarge</p>
<div id="Images">
<div class="Spacer"></div>
<% If IsIE Then Response.Write("<div style=""width: 1px; height: 236px; float: right;""></div>") %>
<asp:Repeater id="repGallery" runat="server">
<ItemTemplate>
<div class="Thumb"><a href="/images/gallery/<%= Request.QueryString("category") %>/<%# DataBinder.Eval(Container.DataItem, "Name") %>" title="<%# Left(DataBinder.Eval(Container.DataItem, "Name"), Len(DataBinder.Eval(Container.DataItem, "Name")) - 4) %>"><img src="/controls/thumbnail.aspx?filename=/images/gallery/<%= Request.QueryString("category") %>/<%# DataBinder.Eval(Container.DataItem, "Name") %>&width=100" alt="<%# DataBinder.Eval(Container.DataItem, "Name") %>" /></a></div>
</ItemTemplate>
</asp:Repeater>
<div class="Spacer"></div>
</div>
</div>
</form>
</body>
</html>
And here's thumbnail.aspx, which generates the thumbnail of the image on the fly...
Code:
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
Dim objImage, objThumbnail As System.Drawing.Image
Dim strFilename As String
Dim shtWidth, shtHeight As Short
Sub Page_Load
strFilename = Server.MapPath(Request.QueryString("filename"))
Try
objImage = objImage.FromFile(strFilename)
Catch
objImage = objImage.FromFile(Server.MapPath("/images/error.gif"))
End Try
If Request.QueryString("width") = Nothing Then
shtHeight = objImage.Height
ElseIf Request.QueryString("width") < 1 Then
shtHeight = 100
Else
shtHeight = Request.QueryString("width")
End If
shtWidth = objImage.Width / (objImage.Height / shtHeight)
objThumbnail = objImage.GetThumbnailImage(shtWidth, shtHeight, Nothing, System.IntPtr.Zero)
Response.ContentType = "image/jpeg"
objThumbnail.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
objImage.Dispose()
objThumbnail.Dispose()
End Sub
</script>
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
|