two effective ways to do this.. You can create a gif file that is transparent except for your watermark and create it the same size, or close to, of the default image. Then on your page, set the background of a div to the default image, and the size of the div to the size of the default image. Then inside the div, place the of the watermark. This stops most people from copying and saving your pictures.
Anther way is to have it done dynamically at runtime. This creates a krap load of resources on your server and will always as long as any image is called. I would recommend staying away from it.
The way that I do it is that I upload the picture to my server through a website, save a temp of it, open the temp, resize and then add a watermark to it (just text at the moment).. then save it to the name and directory wanted. I do this both for thumbnails and main images. I'll give you a resize function and a watermark function that you might want to use.
You need these namespaces:
<![CDATA[<%@ import Namespace="System.IO" %>
<![CDATA[<%@ import Namespace="System.Drawing.Imaging" %>
<![CDATA[<%@ import Namespace="System.Drawing" %>
<![CDATA[<%@ import Namespace="System.Drawing.Drawing2D" %>
resize function:
Function generateThumbnail(ByVal newWidth As Integer, ByVal strFileName As String, ByVal newStrFileName As String)
Dim bmp As Bitmap
Dim newHeight As Integer
Dim resized As Bitmap
Dim FilePath As String = Server.MapPath("/images/")
bmp = System.Drawing.Image.FromFile(FilePath & strFileName & ".jpg")
newHeight = (newWidth/bmp.width)*bmp.Height
resized = new Bitmap(newWidth,newHeight)
newStrFileName = FilePath & newStrFileName & ".jpg"
Dim g as Graphics = Graphics.FromImage(resized)
g.SmoothingMode = SmoothingMode.HighQuality
g.CompositingQuality = CompositingQuality.HighQuality
g.InterpolationMode = InterpolationMode.High
g.DrawImage(bmp, new Rectangle(0,0,resized.Width,resized.Height),0,0,bmp.Width,bmp.Height,GraphicsUnit.Pixel)
g.Dispose()
resized.Save(newStrFileName,ImageFormat.Jpeg)
bmp.dispose()
End Function
watermark function:
Function watermark(ByVal strFileName As String, ByVal newStrFileName As String)
Dim FilePath As String = Server.MapPath("/images/")
Dim bmp As Bitmap = System.Drawing.Image.FromFile(FilePath & strFileName & ".jpg")
Dim strWatermark As String = "WATERMARK TEXT"
Dim canvas As Graphics = Graphics.FromImage(resized)
Dim StringSizeF As SizeF, DesiredWidth As Single, wmFont As Font, RequiredFontSize As Single, Ratio As Single
newStrFileName = FilePath & newStrFileName & ".jpg"
wmFont = New Font("Verdana", 6, FontStyle.Bold)
DesiredWidth = bmp.Width * .75
StringSizeF = canvas.MeasureString(strWatermark, wmFont)
Ratio = StringSizeF.Width / wmFont.SizeInPoints
RequiredFontSize = DesiredWidth / Ratio
wmFont = New Font("Verdana", RequiredFontSize, FontStyle.Bold)
canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.Beige), 0, 0)
canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 0, 0, 0)), 2, 2)
canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 255, 255, 255)), 0, 0)
canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 0, 0, 0)), 2, 2)
canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 255, 255, 255)), 0, 0)
bmp.SetResolution(96, 96)
bmp.Save(newStrFileName,ImageFormat.Jpeg)
canvas.dispose()
bmp.dispose()
End Function
Now these functions I have edited before I put on here, so if there's a flaw let me know as I haven't had time to test them. Anyway, you need to save your uploaded image first, or at least know the location of the ones you want to watermark or resize. An example on how to use these are:
''resize
''if you wish to have the ".jpg" within the function command, remove it from
''within the function and you can have "resizeme.jpg" and "resized.jpg"
generateThumbnail(100,"resizeme","resized")
''watermark
''if you wish to have the ".jpg" within the function command, remove it from
''within the function and you can have "watermarkme.jpg" and "watermarked.jpg"
watermark("watermarkme","watermarked")
These functions only do JPEGS, so if you try another file format, it will fail on you.