AspJpeg Add watermark Complete Method _asp Foundation

Source: Internet
Author: User
Tags border color save file
AspJpeg is a persits-produced shareware, the probationary period is 30 days, you can download here: Http://www.persits.com/aspjpeg.exe. The latest version number is 1.3.
AspJpeg is a very powerful image processing component, with which you can easily make thumbnails of pictures and add watermarks to images. Here is a brief description of how to use it:
You will first perform the downloaded EXE file and install the component
1. Make thumbnails for pictures

<% \\\ ' Establish an example
Dim Jpeg,path
Set Jpeg = Server.CreateObject ("Persits.jpeg")
\\\ ' picture location
Path = Server.MapPath ("Images") & "\\\\clock.jpg"


\\\ ' Open
Jpeg.open Path

\\\ ' Set thumbnail size (this ratio is set to 50%)
Jpeg.width = JPEG.ORIGINALWIDTH/2
Jpeg.height = JPEG.ORIGINALHEIGHT/2

\\\ ' save thumbnails to specified folder
Jpeg.save Server.MapPath ("Images") & "\\\\clock_small.jpg"

\\\ ' Logoff instance
Set Jpeg = Nothing
%>

<P>



2. Add watermark function to picture
<%
Dim Jpeg
\\\ ' Establish an example
Set Jpeg = Server.CreateObject ("Persits.jpeg")
\\\ ' Open the target picture
Jpeg.open Server.MapPath ("Images/dodge_viper.jpg")

\\\ ' Add text watermark
Jpeg.Canvas.Font.Color = &hff0000\\\ ' Red
Jpeg.Canvas.Font.Family = "Song Body"
Jpeg.Canvas.Font.Bold = True
Jpeg.Canvas.Print, "Copyright (c) cnmaya.org"

\\\ ' Save file
Jpeg.save Server.MapPath ("Images/dodge_viper_framed.jpg")

\\\ ' Logoff object
Set Jpeg = Nothing
%>


Last done a picture watermark, the effect is very poor, no way to make the picture background transparent, with the background transparent GIF will automatically fill into white. With the function of removing a certain color, the picture color is always impure, the effect that comes out is stained dot. Today brainwave, put these two together, with the background transparent GIF, and extract watermark background, it was successful!

Ogvbox. Canvas.Pen.Color = &h000000 \\\ '//Border color
Ogvbox. Canvas.Pen.Width = 1 \\\ '//Border thickness
Ogvbox. Canvas.Brush.Solid = False \\\ '///Picture border fill Color
Ogvbox. DrawImage Ogvbox. Width-210, Ogvbox. Height-74, Logobox, 0.3,&hffffff \\\ '//Add the picture's position coordinates (adds the watermark picture), I use the picture size to subtract the watermark size, adds the watermark to the lower right corner. The parameter order is: horizontal coordinate, vertical coordinate, watermark picture address, mercury transparency, extraction color (&h represents 16)
Ogvbox. Canvas.bar 0, 0, Ogvbox. Width, Ogvbox. Height \\\ '//Picture border line position coordinates and size
Ogvbox. Save Server.MapPath (imagename) \\\ '//Generate file
\ '//------pollener.com AspJpeg Component Preview and watermark generation------start------
\ ' Create a preview Picture: Call CreateView (path to original file, preview filename and path)
Sub CreateView (Imagename,tempfilename)
\ ' Define variables.
Dim Previewimagefoldername
Dim Ogvbox,objfont
Dim Logobox,logopath
Logopath = Server.MapPath ("Images") & "\\shuiyin.gif"//Add the path and filename of the picture (my name is forum \\images\\shuiyin.gif).

Select Case Upload_viewtype
Case 0
\ '---------------------createpreviewimage---------------
Set ogvbox = Server.CreateObject ("Createpreviewimage.cgvbox")
Ogvbox. Setsavepreviewimagepath=server.mappath (tempfilename) \ ' Preview map to store the path.
Ogvbox. Setpreviewimagesize =setpreviewimagesize \ ' preview width.
Ogvbox. Setimagefile = Trim (Server.MapPath (imagename)) \ imagename The physical path of the original file.
\ ' Create a file for the preview diagram.
If Ogvbox. Doimageprocess=false Then
Response.Write "Generate Preview Map error:" & Ogvbox. Geterrstring
End If
Case 1
\ '---------------------AspJpegV1.2---------------
Set Logobox = Server.CreateObject ("Persits.jpeg")
\ '//recommend do not use both picture and text watermark, this code is for using image watermark.
Logobox.open logopath \//Read the added picture.

\ '//Reset the size of the picture.
Logobox.width = 186 \//The width value (pixel) of the picture used for the watermark.
Logobox.height = 52 \//The height value (pixel) of the picture used for the watermark.
\ '//Add watermark.
Set Ogvbox = Server.CreateObject ("Persits.jpeg")
\//Read the original file to be processed.
Ogvbox. Open Trim (Server.MapPath (imagename))
If Ogvbox. Originalwidth<cint (imagewidth) or Ogvbox. Originalheight<cint (ImageHeight) Then
F_viewname= ""
Set Ogvbox = Nothing
Exit Sub
Else
If imagemode<> "" and fileext<> "gif" Then \//If this line is changed to if imagemode<> "" Then can also add a watermark to the uploaded GIF image, But those animated GIF after adding a watermark is only the first frame, according to your needs discretion.

\//About modifying font and text colors.
\ '//ogvbox. Canvas.Font.Color = &h0000ff \//Watermark text color, &h enter color value after.
\ '//ogvbox. Canvas.Font.Size = 18 \//The size of the watermark text.
\ '//ogvbox. Canvas.Font.Family = "Arial" \///Watermark text font name.
\ '//ogvbox. Canvas.Font.ShadowColor = &h000000 \//Watermark text shadow color.
\ '//ogvbox. Canvas.Font.ShadowXoffset = 1 \//Watermark text Shadow right offset pixel value, enter negative to left offset.
\ '//ogvbox. Canvas.Font.ShadowYoffset = 1 \//Watermark Text shadow downward offset pixel value, input negative to the right offset.
\ '//ogvbox. Canvas.Font.Quality = 3 \//Watermark text clarity, from 0~4, transform is not very large, recommended with 2 or 3.
\ '//ogvbox. Canvas.Font.Bold = True \///Watermark text is bold, true= bold false= normal.

\ ' Ogvbox. Canvas.print, Imagemode \ '//Watermark text starting coordinates (in pixels).
Ogvbox. Canvas.Pen.Color = &h000000 \//Increase the border color of the picture after the watermark.
Ogvbox. Canvas.Pen.Width = 1 \//Increase the border width of the picture after the watermark.
Ogvbox. Canvas.Brush.Solid = False \//Whether the color is filled inside the border, you can try the effect when the value is true ^o^
Ogvbox. DrawImage ogvbox.width-186, ogvbox.height-52, logobox, 0.5 \ '//watermark image's starting coordinates, I'm here ogvbox.width-186, ogvbox.height-52, The picture in the lower right corner, because my picture width is 186, High is 52, so write, you can adjust according to your own picture. 0.5 is transparency, I am here translucent, 1 means opaque, you can also try 0.7 or 0.8 of the effect.
Ogvbox. Canvas.bar 0, 0, Ogvbox. Width, Ogvbox. Height \//watermark available range. I am here to show the upper left corner to the lower right corner, that is, the whole picture can be added to the watermark.
Ogvbox. Save Server.MapPath (imagename) \///To generate a picture file with the watermark added based on the above parameters.
End If
Ogvbox. Width = ImageWidth
Ogvbox.height = ImageHeight
\ ' Ogvbox.height = Ogvbox. Originalheight*imagewidth\\ogvbox. OriginalWidth
Ogvbox. Sharpen 1, 120
Ogvbox. Save Server.MapPath (tempfilename) \//Generate a preview picture of the image after the watermark is added.
End If
Set logobox=nothing
\ '//------pollener.com AspJpeg Component Preview and watermark generation------END------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.