labs.insert-title.com

Quick Watermark

The Code: watermark.aspx

	
<%@ Page Explicit="True" Language="VB" Debug="True" %> 
<%@ Import Namespace="system.drawing" %>
<%@ Import Namespace="system.drawing.imaging" %>
<%@ Import Namespace="system.drawing.drawing2d" %>
<%@ Import Namespace="system.io" %>
<script runat="server">
  
  dim Filename as String
  dim Width, Height, shadowSize as Integer
  dim Bitmap as system.drawing.bitmap
  dim ImgFormat as ImageFormat
  dim Img as System.Drawing.Image
  Dim baseMap as Bitmap 
	dim top, left as Integer  
sub CreateGraphic()
	Dim letterBrush as SolidBrush = new SolidBrush(Color.FromArgb(50, 255, 255, 255))
	Dim shadowBrush as SolidBrush = new SolidBrush(Color.FromArgb(50, 0, 0, 0))
	Dim fontTitle as Font = new Font("tahoma", 20, FontStyle.Bold)
	Filename = Request.QueryString("filename")
	Filename = server.mappath(Filename)
	ImgFormat = ImageFormat.jpeg : response.contenttype="image/jpeg"  ' Default=jpeg '
	Img = system.drawing.image.FromFile(Filename)    
	Width  = Img.Width
	Height = Img.Height
  	baseMap = new Bitmap(Width,Height)
  	Dim myGraphic as Graphics = Graphics.FromImage(baseMap)
  	with myGraphic
		.DrawImage(Img, 0,0, Width,Height)
		.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
		.DrawString("LABS.INSERT-TITLE.COM", fontTitle, shadowBrush, 5, 60)
		.DrawString("LABS.INSERT-TITLE.COM", fontTitle, letterBrush, 7, 62)
	end with
	Img.dispose()

end sub
</script>
<%
CreateGraphic
baseMap.Save(Response.OutputStream, ImageFormat.JPEG)
baseMap.dispose()
Img = Nothing   
response.end
%>
</script>

Usage

	

Example






Discussion

Chris Mc

Fantastic script, just what i was after!

Gabe Taylor

Why do I get the following error? Am I missing some ASP component?

Thanks.

-------------

Active Server Pages error `ASP 0221`

Invalid @ Command directive

/onlocation/test.asp, line 1

The specified `Page Explicit="True" Language="VB" Debug="True" ` option is unknown or invalid.

-------------

Gabe Taylor

Please email reply to gabe@cascadecomputing.com

Joe Maddalone

Save the first chunk of code as "watermark.aspx"

Then in your ASP page make the src of the image:

<img src="watermark.aspx?filename=FILENAME.JPG" />

Gabe Taylor

Hmm... I receive the following:

Microsoft VBScript runtime error `800a01a8`

Object required: ``

/onlocation/images.html, line 4

Line 4 being the one that has <img src="watermark.aspx?filename=FILENAME.JPG" />

Is there a component that I need for this to work that would not be part of ASP 3.0?

Thanks.

Joe Maddalone

This is ASP.NET you need at least the .Net Framework 1.0 or 1.1, which you can download for free form Microsoft. Just check Google for ".Net Framework download".

FILENAME.JPG... replace that with the actualy filename of an actual image, on your actual server.

Antonio

Great Code, And Thanks for share it. I got some questions: Why this piece of code is used twice? <% CreateGraphic baseMap.Save(Response.OutputStream, ImageFormat.JPEG) baseMap.dispose() Img = Nothing response.end %>

And A further question? After Run it the process aspnet_wp.exe Start. Even If I move to another page the process is running. How Stop this proccess?

Thanks in advance

Joe Maddalone

THe doubling up on the <% CreateGraphic baseMap... line is a typo - I`ll fix that today.

Your other question is something I will look into for you.

Paco

if possible include a logo in the watermark

rogotenin

Hi I am Lucy, I have found your website while searching for some info at Google. Your site has helped me in a big way. G`night

Have Fun

on your vacation wyvern

Joe Maddalone

Will Do

porty

gracias! las ñ y los acentos no los reconoce en el filename

New comments are currently disabled, you can find me @joemaddalone Comments temporarily disabled for now, you can find me @joemaddalone