| | |
add watermark in image
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 84
Reputation:
Solved Threads: 4
i want to add watermark in image.i am using image handler. its not properly working. i want to add watermark at runtime only no need for original image.in my home page i have 25 thumbnail images. when i click any one of the image it goes next page and display large image at that time only i need watermark in image.please reply as early as possible.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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 <img ...> 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:
resize function:
watermark 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:
These functions only do JPEGS, so if you try another file format, it will fail on you.
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:
ASP.NET Syntax (Toggle Plain Text)
<%@ import Namespace="System.IO" %> <%@ import Namespace="System.Drawing.Imaging" %> <%@ import Namespace="System.Drawing" %> <%@ import Namespace="System.Drawing.Drawing2D" %>
ASP.NET Syntax (Toggle Plain Text)
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
ASP.NET Syntax (Toggle Plain Text)
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
ASP.NET Syntax (Toggle Plain Text)
''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")
Last edited by SheSaidImaPregy; Jan 18th, 2008 at 10:51 am.
•
•
Join Date: Dec 2007
Posts: 84
Reputation:
Solved Threads: 4
thanks.
i want watermark only at runtime.no need to save with watermark and also i am using .jpg,.gif,.tif,.png image formats.During image upload,resize functions are over.when clicking thumb image in first page it displays big image in second page. these are done. i need only one thing add watermark when display image thats the problem
i want watermark only at runtime.no need to save with watermark and also i am using .jpg,.gif,.tif,.png image formats.During image upload,resize functions are over.when clicking thumb image in first page it displays big image in second page. these are done. i need only one thing add watermark when display image thats the problem
Last edited by nandhinijp; Jan 21st, 2008 at 5:36 am.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
for images at runtime, follow this article. it works and is a good way to do things, however I do not believe in putting so much process on the server everytime an image is requested. But that's my take on it 
http://www.codeproject.com/KB/aspnet...geHandler.aspx

http://www.codeproject.com/KB/aspnet...geHandler.aspx
•
•
Join Date: Dec 2007
Posts: 84
Reputation:
Solved Threads: 4
hi,
I enclosed one word doc.there are one class file and webconfig details.In that class file image path spcified like
Image image = Image.FromFile(context.Request.PhysicalPath);.
that means watermark image applied for all displayed images. its working very good.but i dont want to show watermark for all images. if i integrate that class file with my project its totally struck.. because my site like photo upload.please verify that class file and give solution.
I enclosed one word doc.there are one class file and webconfig details.In that class file image path spcified like
Image image = Image.FromFile(context.Request.PhysicalPath);.
that means watermark image applied for all displayed images. its working very good.but i dont want to show watermark for all images. if i integrate that class file with my project its totally struck.. because my site like photo upload.please verify that class file and give solution.
•
•
Join Date: Dec 2007
Posts: 84
Reputation:
Solved Threads: 4
U told to put all the coding within a function. that class contains 3 fun and implements IHttpHandler.how to use these in .aspx page include IHttpHandler.i want one and only thing thats at runtime just i click the thumb and corresponding large image will load with watermark.if any other methods to put just watermark in <img> tag.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
well your web.config file is being called everytime your page is. Within your web.config file, you have the ImageHandler class being called for every .jpg, etc. If you want only the large image to watermark, then I would suggest creating a unique string within the images' name so when it is called, ONLY that image will be watermarked. An example of this:
Do you understand?
ASP.NET Syntax (Toggle Plain Text)
Large Image Names: terry-123WM123.jpg beachparty-123WM123.jpg howdy-123WM123.jpg or picture123WM123.jpg terry123WM123.jpg etc. Now in your web.config file, change your HTTP Handler that you put in there [ <httpHandlers> <add verb="*" path="*.jpg,*.gif" type="ImageHandler,Home" validate="false"/> </httpHandlers> ] to [ <httpHandlers> <add verb="*" path="*123WM123.jpg,*123WM123.gif" type="ImageHandler,Home" validate="false"/> </httpHandlers> ] The star (*) symbolizes that anything with a jpg or gif end tag will be run with the watermark code. Therefore, if you only want specific images to contain the watermark, add a special unique string within the files being called, much like "123WM123". This will call anything that ends with "123WM123.jpg" and "123WM123.gif". Now I suggest doing something more practical like: *WML.jpg and *WML.gif. WML meaning watermarklarge (for me)
Last edited by SheSaidImaPregy; Jan 28th, 2008 at 10:23 am.
![]() |
Similar Threads
- Program to convert video to Flash AND watermark it? (Graphics and Multimedia)
- Auto replace hotlinked Image Javascript? (JavaScript / DHTML / AJAX)
- Java Applet [Move Image] (Java)
- DIV Help! (HTML and CSS)
Other Threads in the ASP.NET Forum
- Previous Thread: how to design a website
- Next Thread: Application Variables
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal formview gridview gudi iis javascript list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview unauthorized validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






