Protect your site photos with a signature

Four years ago i started my web programming experience. The first site i made is www.irclove.com a social networking site. After two years i noticed that someone stoled my users photo and posted it on other sites or blogs so i decided to add a signature on the photos to easily identify them on other sites. I know that signature can be removed with photoshop or other softwares but i think that if someone (a stupid one) needs a photo to post somewhere he prefers one with no extra work required :)

Here is the code i wrote to add signature to my website photos.
I preferred to use just the contour of text with transparent body to preserve the portion of photo where the text is placed.

I hope it helps :)

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
 
Public Class SignPhoto1
    Inherits System.Web.UI.Page
 
#Region " Codice generato da Progettazione Web Form "
 
    'Chiamata richiesta da Progettazione Web Form.
    <System.Diagnostics.DebuggerStepThrough()>
       Private Sub InitializeComponent()
 
       End Sub
 
    Private designerPlaceholderDeclaration As System.Object
 
    Private Sub Page_Init(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Init
        InitializeComponent()
    End Sub
 
#End Region
 
    Private Sub Page_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load

        Dim objGraphics As Graphics
        Dim imgBack As System.Drawing.Image
        Dim ImgFile As String
        Dim ImgID As String

        Try
            ImgID = Request("ID").ToString().Replace("'", "''")
            ImgID = ImgID.Replace("\\", "\\\\")
        Catch
            ImgID = "err" 'use a default error image
        End Try

        If Not IsNumeric(ImgID) Then
            ImgID = "err" 'default error image
        End If

        ImgFile = Server.MapPath("public/Photo/") + ImgID + ".jpg"
        imgBack = System.Drawing.Image.FromFile(ImgFile)
        Dim objBitMap As New Bitmap(imgBack)
 
        objGraphics = Graphics.FromImage(objBitMap)
        Dim pth As New GraphicsPath
        'create the outline for the text "www.IRCLove.com"

        pth.AddString("www.IRCLove.com",_
            New FontFamily("Verdana"),_
            FontStyle.Bold, 22,_
            New PointF(5, objBitMap.Height - 30),_
            StringFormat.GenericTypographic)

        Dim outline As New Pen(Color.White, 1)
        'select High Quality smoothing mode for better results
        objGraphics.SmoothingMode = SmoothingMode.HighQuality

        'this is slower but grants a good quality result
        objGraphics.TextRenderingHint = _
             Text.TextRenderingHint.SingleBitPerPixelGridFit

	'let's draw the text outline
        objGraphics.DrawPath(outline, pth)
        outline.Dispose()
        pth.Dispose()
 
        objBitMap.Save(Response.OutputStream, ImageFormat.Jpeg)
        objBitMap.Dispose()
        objBitMap = Nothing
        objGraphics.Dispose()
        objGraphics = Nothing
        imgBack.Dispose()
        imgBack = Nothing
    End Sub
 
End Class

Download this code: SignPhoto.aspx.txt



Leave a Reply