<%@Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="system.drawing" %>
<%@Import Namespace="System.Drawing.Drawing2D" %>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function
Sub Page_Load(sender as Object, e as EventArgs)
'Get the image name – yourimage.jpg – from the query String
Dim imageURL as String = Request.QueryString("img")
Dim imageHeight as Integer
'Set the thumbnail width in px – the width will be calculated later to keep the original ratio.
Dim imageWidth as Integer = 300
Dim CurrentimgHeight As Integer
Dim CurrentimgWidth As Integer
imageUrl = "d:\inetpub\webs\miositocom\" & imageURL
Dim fullSizeImg as System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(imageUrl)
CurrentimgHeight = fullSizeImg.Height
CurrentimgWidth = fullSizeImg.Width
imageHeight = CurrentimgHeight / CurrentimgWidth * imageWidth
'This will only work for jpeg images
Response.ContentType = "image/jpeg"
If imageHeight > 0 and imageWidth > 0 then
Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
dummyCallBack = New _
System.Drawing.Image.GetThumbnailImageAbort(Addres sOf ThumbnailCallback)
Dim thumbNailImg as System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, _
dummyCallBack, IntPtr.Zero)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(thumbNailImg)
dim StringSizeF as SizeF, DesiredWidth as Single, wmFont as Font, RequiredFontSize as Single, Ratio as Single
Dim strWatermark = "DMXZone"
'Set the watermark font
wmFont = New Font("Verdana", 14, FontStyle.Bold)
DesiredWidth = imagewidth * .5
'use the MeasureString method to position the watermark in the centre of the image
StringSizeF = g.MeasureString(strWatermark, wmFont)
Ratio = StringSizeF.Width / wmFont.SizeInPoints
RequiredFontSize = DesiredWidth / Ratio
wmFont = New Font("Verdana", RequiredFontSize, FontStyle.Bold)
'Sets the interpolation mode for a high quality image
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic
g.DrawImage(fullSizeImg, 0, 0, imagewidth, imageheight)
g.SmoothingMode = SmoothingMode.HighQuality
Dim letterBrush as SolidBrush = new SolidBrush(Color.FromArgb(50, 255, 255, 255))
Dim shadowBrush as SolidBrush = new SolidBrush(Color.FromArgb(50, 0, 0, 0))
'Enter the watermark text
g.DrawString("DMXZone", wmFont, shadowBrush, 75, (imageHeight * .5) - 36)
g.DrawString("DMXZone", wmFont, letterBrush, 77, (imageHeight * .5) - 38)
thumbNailImg.Save(Response.OutputStream, ImageFormat.jpeg)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.jpeg)
End If
'Important, dispose of the image – otherwise the image file will be locked by the server for several minutes
fullSizeImg.Dispose()
End Sub
</script>