Create thumbnail.aspx Page
<%@ Import Namespace=System.Drawing %>
<%@ Import Namespace=System %>
<%@ Import Namespace=System.Web %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
' Initialize objects
Dim objImage, objThumbnail As System.Drawing.Image
Dim strServerPath, strFilename As String
Dim shtWidth, shtHeight As Short
Dim PRTarget, PROriginal As Short
' Get image folder path on server - use "\" string if root
' strServerPath = Server.MapPath("images\")
' Retrieve name of file to resize from query string
' strFilename = strServerPath & Request.QueryString("filename")
strFilename = Request.QueryString("FileName")
' Retrieve file, or error.gif if not available
Try
objImage = objImage.FromFile(Server.MapPath(strFilename))
Catch
objImage = objImage.FromFile(Server.MapPath("images/default.gif"))
End Try
' Retrieve width from query string
If Request.QueryString("width") = Nothing Then
shtWidth = objImage.Width
ElseIf Request.QueryString("width") < 1 Then
shtWidth = 100
Else
shtWidth = Request.QueryString("width")
End If
If Request.QueryString("height") = Nothing Then
shtHeight = objImage.Height
ElseIf Request.QueryString("height") < 1 Then
shtHeight = 100
Else
shtHeight = Request.QueryString("height")
End If
PROriginal = objImage.Width / objImage.Height
PRTarget = shtWidth / shtHeight
if objImage.Width > objImage.Height Then
' Work out a proportionate height from width
shtHeight = objImage.Height / (objImage.Width / shtWidth)
Else
' Work out a proportionate width from height
shtWidth = objImage.Width / (objImage.Height / shtHeight)
End If
' Create thumbnail
If objImage.Width<=shtWidth And objImage.Height<=shtHeight Then
objThumbnail = objImage
Else
objThumbnail = objImage.GetThumbnailImage(shtWidth, _
shtHeight, Nothing, System.IntPtr.Zero)
End If
' Send down to client
Response.ContentType = "image/jpeg"
objThumbnail.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
' Tidy up
objImage.Dispose()
objThumbnail.Dispose()
End Sub
</script>
</html>
-
The following article discusses the WPF command binding feature with relation to Mouse clicks. One of WPF powerful features is the bindin...
-
SQL Server has never been short of ways to read from and write to files and it is always better to use the standard techniques provided b...
-
In this article we will look at the basics of Angular.Js. This is the first part of an article series. The main objective of this series i...