here is the C# code converted to VB.NET. It contains a few minor modifications that are specific to my site. Anyone using either set of code for the Personal Sit Kit will need to modify it to suit their needs.
<%@ WebHandler Language="VB" Class="Handler" %>
imports System.IO
Imports System.Drawing
Imports System.Drawing.Image
Public Class Handler
Implements IHttpHandler
'the max size of the thumbnail
Const MaxDim As Integer = 120
Dim imagedirectory As String = ""
Dim imagename as String = ""
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
With context
If Not .Request.QueryString("Dir") Is Nothing And .Request.QueryString("Dir") <> "" Then
imagedirectory = .Request.QueryString("Dir")
Else
Exit Sub
End If
If Not .Request.QueryString("File") Is Nothing And .Request.QueryString("File") <> "" Then
imagename = .Request.QueryString("File")
imagename = imagename.Replace("\", "/")
imagename = imagename.Replace("//", "/")
End If
With .Response
.contenttype = "image/jpeg"
.Cache.SetCacheability(HttpCacheability.Public)
.Cache.SetExpires(DateTime.Now.AddDays(1))
End With
'find the image that was requested
Dim file As String = ""
file = imagedirectory & imagename
file = .Request.MapPath(file)
'load the image
Using img As Image = New Bitmap(file)
'do some math to resize the image
Dim h As Integer = img.Height
Dim w As Integer = img.Width
Dim b As Integer
If h > w Then
b = h
Else
b = w
End If
Dim per As Double
If b > MaxDim Then
per = ((MaxDim * 1.0) / b)
Else
per = 1.0
End If
h = CType((h * per), Integer)
w = CType((w * per), Integer)
'create the thumbnail image
Using img2 As Image = img.GetThumbnailImage(w, h, New Image.GetThumbnailImageAbort(AddressOf Abort), IntPtr.Zero)
'emit it to the response stream,
img2.Save(.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
End Using
End Using
End With
End Sub
Private Function Abort() As Boolean
Return False
End Function