Aspjpeg is a powerful image processing component. It can easily create thumbnails and add watermark images. So, do you know the complete use of Aspjpeg to add watermarks? Don’t worry, let’s follow the editor of the Wrong New Technology Channel today!
Here is a brief introduction to how to use it:
You must first execute the downloaded exe file and install the component
1. Create thumbnails for pictures
<% ///' Create an instance
Dim Jpeg, Path
Set Jpeg = Server.CreateObject("Persits.Jpeg")
///' Location of the picture
Path = Server.MapPath("images") & "/////clock.jpg"
///' Open
Jpeg.Open Path
///' Set the thumbnail size (the scale is set to 50%)
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
///' Save the thumbnails to the specified folder
Jpeg.Save Server.MapPath("images") & "/////clock_small.jpg"
///' Logout instance
Set Jpeg = Nothing
%>
>
2. Add watermark function to the picture
<%
Dim Jpeg
///' Create an instance
Set Jpeg = Server.CreateObject("Persits.Jpeg")
///' Open the target image
Jpeg.Open Server.MapPath("images/dodge_viper.jpg")
///' Add text watermark
Jpeg.Canvas.Font.Color = &HFF0000///' Red
Jpeg.Canvas.Font.Family = "安安"
Jpeg.Canvas.Font.Bold = True
Jpeg.Canvas.Print 10, 10, "Copyright (c) Cnmaya.org"
///' Save the file
Jpeg.Save Server.MapPath("images/dodge_viper_framed.jpg")
///'Login the object
Set Jpeg = Nothing
%>
I made a picture watermark last time, but the effect was very poor. I couldn't make the picture transparent in the background. Using a transparent background gif will automatically fill it into white. With the function of removing a certain color, the color of the picture is always impure, and the effect is spotty. Today I had an idea, combined these two, used a transparent gif with the background, and extracted the watermark background color, and it was indeed successful!
ogvbox.Canvas.Pen.Color = &H000000 ///'// The color of the border
ogvbox.Canvas.Pen.Width = 1 ///'/ The thickness of the border
ogvbox.Canvas.Brush.Solid = False ///'/ Whether to fill the color in the border of the picture
ogvbox.DrawImage ogvbox.Width-210, ogvbox.Height-74, Logobox ,0.3,&HFFFFFF ///'/ Add the position coordinates of the image (add watermark image). I subtract the watermark size from the image size and add the watermark to the lower right corner. The parameter order is: horizontal coordinates, vertical coordinates, watermark image address, mercury transparency, extracted color (&H means hexadecimal)
ogvbox.Canvas.Bar 0, 0, ogvbox.Width, ogvbox.Height ///'// The position coordinates and size of the border line of the image
ogvbox.Save Server.MapPath(imagename) ///'/ Generate file
/'//-------Pollener.com Preview and watermark generation of AspJpeg components---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/'Create a preview image: call CreateView (the path of the original file, the preview file name and path)
Sub CreateView(imagename,tempFilename)
/'Define the variable.
Dim PreviewImageFolderName
Dim ogvbox,objFont
Dim Logobox, LogoPath
LogoPath = Server.MapPath("images") & "//shuiyin.gif" /'//Add the path and file name of the image (My is forum //images//shuiyin.gif).
Select Case upload_ViewType
Case 0
/'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
set ogvbox = Server.CreateObject("CreatePreviewImage.cGvbox")
ogvbox.SetSavePreviewImagePath=Server.MapPath(tempFilename) /'Preview image storage path.
ogvbox.SetPreviewImageSize =SetPreviewImageSize /'PreviewPreviewPreviewPreviewWidth.
ogvbox.SetImageFile = trim(Server.MapPath(imagename)) /'imagename The physical path to the original file.
/'Create a file for preview diagram.
If ogvbox.DoImageProcess=false Then
Response.write "Generate preview image error:"& ogvbox.GetErrString
End If
Case 1
/'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Set Logobox = Server.CreateObject("Persits.Jpeg")
/'// It is recommended not to use image and text watermarks at the same time. This code uses image watermarks.
Logobox.Open LogoPath /'//Read the added image.
/'//Resize the image.
Logobox.Width = 186 /'//Width value (pixel) of the image used as watermark.
Logobox.Height = 52 /'//The height value (pixel) of the image used as the watermark.
/'//Add a watermark.
Set ogvbox = Server.CreateObject("Persits.Jpeg")
/'//Read the original file to be processed.
ogvbox.Open Trim(Server.MapPath(imagename))
If ogvbox.OriginalWidth
Set ogvbox = Nothing
Exit Sub
Else
IF ImageMode<>"" and FileExt<>"gif" Then /'//If you change this line to IF ImageMode<>"" Then you can also add a watermark to the uploaded GIF images, but after adding a watermark to those animation GIFs, you will only have the first frame left. Please handle it as appropriate according to your needs.
/'//About modifying the font and text color.
/'//ogvbox.Canvas.Font.Color = &H0000FF /'//The color of the watermark text, enter the color value after &H.
/'//ogvbox.Canvas.Font.Size = 18 /'//The size of the watermark text.
/'//ogvbox.Canvas.Font.Family = "Arial" /'// Font name of the watermark text.
/'//ogvbox.Canvas.Font.ShadowColor = &H00000 /'// Shadow color of watermark text.
/'//ogvbox.Canvas.Font.ShadowXoffset = 1 /'//The pixel value of the watermark text shadow shifts to the right, and if the negative value is entered, the left will shift.
/'//ogvbox.Canvas.Font.ShadowYoffset = 1 /'//The pixel value of the watermark text shadow shifts downward, and if you enter a negative value, you shift to the right.
/'//ogvbox.Canvas.Font.Quality = 3 /'//The clarity of the watermark text, from 0 to 4, the transformation is not very large, it is recommended to use 2 or 3.
/'//ogvbox.Canvas.Font.Bold = True /'//Is the watermark text in bold? True=bold False=normal.
/'ogvbox.Canvas.Print 10, 10, ImageMode /'// Start coordinates (pixels) of watermark text.
ogvbox.Canvas.Pen.Color = &H00000 /'//Add the border color of the image after the watermark.
ogvbox.Canvas.Pen.Width = 1 /'//Increase the border width of the image after watermark.
ogvbox.Canvas.Brush.Solid = False /'//Whether the border is filled with color, you can try the effect when the value is True^o^
ogvbox.DrawImage ogvbox.width-186, ogvbox.height-52, Logobox, 0.5 /'//The starting coordinates of the watermark image, here ogvbox.width-186, ogvbox.height-52, means that the image is in the lower right corner, because my image is 186 wide and 52 high, so you can adjust it according to your own image by writing this way. 0.5 is transparency, I am translucent here, 1 means opaque, you can also try the effect of 0.7 or 0.8.
ogvbox.Canvas.Bar 0, 0, ogvbox.Width, ogvbox.Height /'//The range of watermark available. Here I mean that the upper left corner to the lower right corner, that is, the watermark can be added to any one of the entire picture.
ogvbox.Save Server.MapPath(imagename) /'//Create an image file with added watermark 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 adding a watermark.
End If
Set Logobox=Nothing
/'//------Pollener.com Preview and watermark generation of AspJpeg component---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (imagewidth) or ogvbox.originalheight
The above is the complete use of Aspjpeg adding watermarks. I believe everyone has a certain understanding. If you want to know more technical information, please continue to pay attention to the wrong new technology channel!