Recommended: How to add or subtract dates in DateAdd function in ASP This article will introduce the use of date addition or subtraction in the DateAdd function in ASP. Those who need to know can refer to it.
1. Add watermark to the pictureCopy the code as follows: www.CuoXIn.com
<%
Dim Jpeg ''''//Declare variables
Set Jpeg = Server.CreateObject("Persits.Jpeg") ''''//Calling component
Jpeg.Open Server.MapPath("aaa.JPG") ''''//Source image location
Jpeg.Canvas.Font.Color = &H000000 ''''//Watermark font color
Jpeg.Canvas.Font.Family = "安安" ''''//Watermark font
Jpeg.Canvas.Font.Size = 14 ''''//Watermark font size
Jpeg.Canvas.Font.Bold = False ''''//Is it bold? Use: True
Jpeg.Canvas.Font.BkMode = &HFFFFF ''''//Font background color
Jpeg.Canvas.Print 10, 10, "Undefeated Naughty Studio" ''''//Watermark text, two numbers 10 are the xy coordinates of the watermark
Jpeg.Save Server.MapPath("aaa_05.jpg") ''''// Generate a new image with a watermark and save location
Set Jpeg = Nothing ''''//Login the component and release the resource
Response.Write "<img src=aaa_05.jpg>" ''''//Show the image after the watermark is generated on this page
%>
2. Generate thumbnails
Copy the code as follows: www.CuoXIn.com
<%
Dim Jpeg ''''//Declare variables
Set Jpeg = Server.CreateObject("Persits.Jpeg") ''''//Calling component
Jpeg.Open Server.MapPath("aaa.JPG") ''''//Original image location
Jpeg.Width = Jpeg.OriginalWidth/4 ''''//Suppose the width of the picture is one-quarter of the original picture
Jpeg.Height = Jpeg.OriginalHeight/4 ''''//Suppose the image height is one-quarter of the original image
Jpeg.Sharpen 1, 130 ''''//Set the sharpening effect
Jpeg.Save Server.MapPath("aaa_small.jpg") ''''//Generate thumbnail location and name
Set Jpeg = Nothing ''''//Login the component and release the resource
Response.Write "<img src=aaa_small.jpg>" ''''//Show the generated thumbnail image on this page
%>
Introduction to advanced usage methods of aspjpeg components
aspjpeg is a very powerful image processing component, in pure English version. However, there have been free versions and cracked versions, but there are not many articles that provide detailed and in-depth introductions to them. Even if there are, they only involve picture thumbnails and picture watermarks. Maybe it's because of pure English.
Here I will talk about the advanced usage of aspjpeg for these issues. The technologies here mainly include:
Picture thumbnail
Picture watermark
Security code technology
Picture cutting
Picture merge
Database support
More infrequently used methods
and some related practical technologies
The only shortcoming point of aspjpeg is that the output method is relatively single. Here, we mainly talk about this output method that saves the image and then calls it. In addition, I am relatively lazy, so some codes are still quoted in the original document, and I will explain what I don’t understand!
Comrades who have studied vb or .net will definitely understand it at a glance. The brush comes. hehe.
1. Picture thumbnail
Copy the code as follows: www.CuoXIn.com
<%
Set Jpeg = Server.CreateObject("Persits.Jpeg") Calling component
Path = Server.MapPath("images") & "/clock.jpg" pending image path
Jpeg.Open Path Open picture
Height and width are 1/2 of the original picture
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
Save the picture
Jpeg.Save Server.MapPath("images") & "/clock_small.jpg"
%>
<IMG SRC="images/clock_small.jpg"> View processed pictures
2. Picture watermark
Copy the code as follows: www.CuoXIn.com
<%
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open Server.MapPath("images/dodge_viper.jpg")
Start writing
Jpeg.Canvas.Font.Color = &H000000'''' white color
Jpeg.Canvas.Font.Family = "Courier New" font
Jpeg.Canvas.Font.Bold = True Whether to thicken
Jpeg.Canvas.Print 10, 10, "Copyright (c) XYZ, Inc."
Print coordinate x Print coordinate y Characters to be printed
The following is the border processing of the image
Jpeg.Canvas.Pen.Color = &H000000'''' black color
Jpeg.Canvas.Pen.Width = 2 Brush Width
Jpeg.Canvas.Brush.Solid = False Whether to bold
Jpeg.Canvas.Bar 1, 1, Jpeg.Width, Jpeg.Height
Start X coordinate Start Y coordinate input length input height
Jpeg.Save Server.MapPath("images/dodge_viper_framed.jpg") Save
%>
3. Security code
The principle of safe ma is similar to adding a watermark. Many friends asked me about specific code techniques, so I will write it out here to share it with you. I won’t tell them about ordinary people. hehe.
Copy the code as follows: www.CuoXIn.com
<%
Functions that generate security codes www.wuyouw.com
function make_randomize(max_len,w_n) max_len generates length, w_n: 0 may contain letters, 1: only for numbers
randomize
for intcounter=1 to max_len
whatnext=int((1-0+1)*rnd+w_n)
if whatnext=0 then
upper=122
lower=97
else
upper=57
lower=48
end if
strnewpass=strnewpass & chr(int((upper-lower+1)*rnd)+lower)
next
make_randomize=strnewpass
end function
%>
Generate a picture of the security code. Of course you need to prepare a background picture in advance
Copy the code as follows: www.CuoXIn.com
<%random_num=make_randomize(4,1) Generates a 4-digit security code
session("random_num")=random_num Why is session called? It is completely meaningless without session security code. hehe
Set Jpeg = Server.CreateObject("Persits.Jpeg") Calling component
Jpeg.Open Server.MapPath("infos/random_pic/random_index.gif") Open the prepared picture
Jpeg.Canvas.Font.Color = &H006699
Jpeg.Canvas.Font.Family = "Arial Black"
Jpeg.Canvas.Font.Bold = false
Jpeg.Canvas.PrintText 0, -2, random_num
jpeg.save Server.MapPath("infos/random_pic/random_index.bmp") Save
%>
<img src="infos/random_pic/random_index.bmp" align="absmiddle">
Do it yourself. hehe.
4. Picture cutting
People who don't know aspjpeg have always thought that they cannot use it to cut.
There is actually such a method
crop x1,y1,x2,y2
Cut the x-coordinate of the upper left corner of the rectangle, the x-coordinate of the lower right corner of the y-coordinate
I'll give a demonstration below
Set Jpeg = Server.CreateObject("Persits.Jpeg")
jpeg.open server.MapPath("/pic/1.gif")
jpeg.width=70
Jpeg.Height = Jpeg.OriginalHeight*70 / jpeg.Originawidth
jpeg.crop 0,0,70,52 Start cutting is actually removing the lower part of more than 52 pixels
jpeg.save server.MapPath("/temp_pic/small_1.gif") Save
How about it, it's very simple
5. Picture merger
Here we want to add the logo image to the dodge_viper.jpg image
In fact, the method of image merging can also be used to dynamically print watermarks.
Copy the code as follows: www.CuoXIn.com
Set Photo = Server.CreateObject("Persits.Jpeg")
PhotoPath = Server.MapPath("images") & "/dodge_viper.jpg"
Photo.Open PhotoPath
Set Logo = Server.CreateObject("Persits.Jpeg")
LogoPath = Server.MapPath("images") & "/clock.jpg"
Logo.Open LogoPath
Logo.Width = 70
Logo.Height = Logo.Width * Logo.OriginalHeight / Logo.OriginalWidth
Photo.DrawImage 0, 0, Logo
Photo.SendBinary
Here we use the output method of sendBinary. Of course, you can also save the changed dodge_viper.jpg first, and then enter it. I personally don’t like using the sendBinary method, and it is easy to make mistakes when the internet speed is slow. Not very good at speed. hehe.
6. Database support
I won't say much here. In fact, it is the Binary method. As we all know, images can only be stored as binary files when stored in the database. So I'm lazy to write the code.
7. More methods
Canvas.Line(Left, Top, Right, Bottom)
Draw a straight line
Canvas.Ellipse(Left, Top, Right, Bottom)
Draw an ellipse
Canvas.Circle(X, Y, Radius)
Draw a circle
Canvas.Bar(Left, Top, Right, Bottom)
Draw a rectangle with the code on it
Canvas.Font.ShadowColor
Text Shadow Color
Canvas.Font.ShadowXOffset As Long
Shadow X coordinate setting
Canvas.Font.ShadowYOffset As Long
Y coordinate setting
Canvas.Font.BkMode As String
Text background
=====================================================
Today I will tell you about the knowledge of ASP adding watermarks to pictures
ASP requires components to add watermarks to images... Commonly used ones include aspjpeg and wsImage developed by Chinese people... The former is free for 30 days... The latter is completely free... Of course we have to use Chinese products... Hehe...
How to register components :
Enter "regsvr32 [Dll path]" at the command prompt
Adding a watermark to the image is nothing more than getting the image size and then writing the watermark on it... The ASP code only serves as a control component. Use the code to explain everything.
1: Obtain the image size (here is expressed by pixel values. Friends who study PhotoShop should understand)
Copy the code as follows: www.CuoXIn.com
<%
set obj=server.CreateObject("wsImage.Resize") ''''''''''''''''''''''''''''''''Call component
obj.LoadSoucePic server.mappath("25.jpg") ''''''''''''''''''''Open the picture, the picture name is 25.jpg
obj.GetSourceInfo iWidth,iHeight
response.write "Image Width:" & iWidth & "<br>" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
response.write "Image Height:" & iHeight & "<br>" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
strError=obj.errorinfo
if strError<>"" then
response.write obj.errorinfo
end if
obj.free
set obj=nothing
%>
2: Add text watermark
Copy the code as follows: www.CuoXIn.com
<%
set obj=server.CreateObject("wsImage.Resize")
obj.LoadSoucePic server.mappath("25.jpg") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
obj.Quality=75
obj.TxtMarkFont = "Chinese Color Cloud" '''''''''''''''''''''''''''''''''''''''''Setting Watermark Text Font
obj.TxtMarkBond = false '''''''''''''''''''''''''''''''''''''''''''''Set the thickness of the watermark text
obj.MarkRotate = 0 ''''''''''''''''''''''''''''The rotation angle of watermark text
obj.TxtMarkHeight = 25 '''''''''''''''''''''''''''''''''''''The height of the watermark text
obj.AddTxtMark server.mappath("txtMark.jpg"), "Take You Out", &H00FF00&, 10, 70
strError=obj.errorinfo '''''''''''''''''''''''''''''''''''''The name of the image is generated, and the text color is the watermark in the position of the image
if strError<>"" then
response.write obj.errorinfo
end if
obj.free
set obj=nothing
%>
Three: Add image watermark
Copy the code as follows: www.CuoXIn.com
<%
set obj=server.CreateObject("wsImage.Resize")
obj.LoadSoucePic server.mappath("25.jpg") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
obj.LoadImgMarkPic server.mappath("blend.bmp") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
obj.Quality=75
obj.AddImgMark server.mappath("imgMark.jpg"), 315, 220,&hFFFFF, 70
strError=obj.errorinfo '''''''''''''''''''''''''''''''''''''The name of the image is generated, and the text color is the watermark in the position of the image
if strError<>"" then
response.write obj.errorinfo
end if
obj.free
set obj=nothing
%>
In fact, adding a watermark to an image is that simple. Then I'm talking about two other main uses of the WsImage.dll component. Including:
Crop the picture and generate the thumbnail of the picture.
As I am used to it, I will add comments to the code:
Cropped pictures :
Copy the code as follows: www.CuoXIn.com
<%
set obj=server.CreateObject("wsImage.Resize")
obj.LoadSoucePic server.mappath("25.jpg")
obj.Quality=75
obj.cropImage server.mappath("25_crop.jpg"),100,10,200,200 '''''''''''''''''''''Define the clip size and generate the image name
strError=obj.errorinfo
if strError<>"" then
response.write obj.errorinfo
end if
obj.free
set obj=nothing
%>
Detailed comment: CropImage uses WsImage's CropImage method. When defining the image generation, 100 and 10 are the cut points in the upper left corner, that is, 100 pixels to the left of the image and 10 pixels at the top. The last two 200s represent the cut broadband and height and height.
Generate image thumbnails:
Copy the code as follows: www.CuoXIn.com
<%
set obj=server.CreateObject("wsImage.Resize")
obj.LoadSoucePic server.mappath("25.jpg") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
obj.Quality=75
obj.OutputSpic server.mappath("25_s.jpg"),0.5,0.5,3 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
strError=obj.errorinfo
if strError<>"" then
response.write obj.errorinfo
end if
obj.free
set obj=nothing
%>
Detailed description:
There are four ways to export thumbnails :
(1) obj.OutputSpic server.mappath("25_s.jpg"),200,150,0
200 is the output width and 150 is the output height. This output form is the forced output width and height, which may cause image deformation.
(2) obj.OutputSpic server.mappath("25_s.jpg"),200,0,1
With 200 as the output width, the output height will be scaled with the column.
(3) obj.OutputSpic server.mappath("25_s.jpg"),0,200,2
With 200 as the output height, the output width will be scaled with the column.
(4) obj.OutputSpic server.mappath("25_s.jpg"),0.5,0.5,3
The first 0.5 means that the generated thumbnail is half the width of the original image, which means the width reduction ratio.
The second 0.5 means that the generated thumbnail is half the height of the original image, which means a high reduction ratio.
The consistent reduction in width and height means that the original image will be scaled down. If the zoom ratio of width and height is greater than 1, the original image will be enlarged.
Reprinted from: http://hi.baidu.com/miracle521/blog/item/e3419133fdc00746ac4b5f25.html
2-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Upload pictures asp.net with watermarks (text watermark, picture watermark, text + picture watermark)
Add watermark to the picture (text watermark, picture watermark, text + picture watermark)
Reproduction image:
Figure 500)this.width=500" border=0<
Watermark 500)this.width=500" border=0<
After adding a watermark to the picture (note the upper right corner + directly below)
500)this.width=500" border=0<
Code:DrawImg.cs
Copy the code as follows: www.CuoXIn.com
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public class DrawImg
{
private string WorkingDirectory = string.Empty ; //Path
private string ImageName = string.Empty; //The processed image
private string ImageWater = string.Empty; //Watermark image
private string FontString = string.Empty; //Watermark text
enum DealType{NONE,WaterImage,WaterFont,DoubleDo}; //Enum command
private DealType dealtype;
public DrawImg()
{}
public string PublicWorkingDirectory
{
get
{
return WorkingDirectory;
}
set
{
WorkingDirectory = value;
}
}
public string PublicImageName
{
get
{
return ImageName;
}
set
{
ImageName = value;
}
}
public string PublicImageWater
{
get
{
return ImageWater;
}
set //If you set a watermark image, it means that you want to use the watermark image effect.
{
dealtype = DealType.WaterImage;
ImageWater = value;
}
}
public string PublicFontString
{
get
{
return FontString;
}
set //If the watermark text is set, it means that the watermark text effect is required.
{
dealtype = DealType.WaterFont;
FontString = value;
}
}
public void DealImage()
{
IsDouble();
switch( dealtype )
{
case DealType.WaterFont: WriteFont(); break;
case DealType.WaterImage: WriteImg(); break;
case DealType.DoubleDo: WriteFontAndImg(); break;
}
}
private void IsDouble()
{
if(ImageWater+""!="" && FontString+""!="")
{
dealtype = DealType.DoubleDo;
}
}
private void WriteFont()
{
//set a working directory
//string WorkingDirectory = @"C:/Watermark_src/WaterPic";
//define a string of text to use as the Copyright message
//string Copyright = "Copyright ?2002 - AP Photo/David Zalubowski";
//create a image object containing the photograph to watermark
Image imgPhoto = Image.FromFile(WorkingDirectory + ImageName);
int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height;
//create a Bitmap the Size of the original photograph
Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
//load the Bitmap into a Graphics object
Graphics grPhoto = Graphics.FromImage(bmPhoto);
//-----------------------------------------------------------------------------------------------------------------------------
//Step #1 - Insert Copyright message
//-----------------------------------------------------------------------------------------------------------------------------
//Set the rendering quality for this Graphics object
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
//Draws the photo Image object at original size to the graphics object.
grPhoto.DrawImage(
imgPhoto, // Photo Image object
new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure
0, // x-coordinate of the portion of the source image to draw.
0, // y-coordinate of the portion of the source image to draw.
phWidth, // Width of the portion of the source image to draw.
phHeight, // Height of the portion of the source image to draw.
GraphicsUnit.Pixel); // Units of measure
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//to maximize the size of the Copyright message we will
//test multiple Font sizes to determine the largest possible
//font we can use for the width of the Photograph
//define an array of point sizes you would like to consider as possible
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int[] sizes = new int[]{16,14,12,10,8,6,4};
Font crFont = null;
SizeF crSize = new SizeF();
//Loop through the defined sizes checking the length of the Copyright string
//If its length in pixels is less then the image width choose this Font size.
for (int i=0 ;i<7; i++)
{
//set a Font object to Arial (i)pt, Bold
//crFont = new Font("arial", sizes[i], FontStyle.Bold);
crFont = new Font("arial",sizes[i],FontStyle.Bold);
//Measure the Copyright string in this Font
crSize = grPhoto.MeasureString(FontString, crFont);
if((ushort)crSize.Width < (ushort)phWidth)
break;
}
//Since all photographs will have varying heights, determine a
//position 5% from the bottom of the image
int yPixlesFromBottom = (int)(phHeight *.05);
//Now that we have a point size use the Copyrights string height
//to determine a y-coordinate to draw the string of the photograph
float yPosFromBottom = ((phHeight - yPixlesFromBottom)-(crSize.Height/2));
//Determine its x-coordinate by calculating the center of the width of the image
float xCenterOfImg = (phWidth/2);
//Define the text layout by setting the text alignment to centered
StringFormat StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Center;
//define a Brush which is semi trasparent black (Alpha set to 153)
SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
//Draw the Copyright string
grPhoto.DrawString(FontString, //string of text
crFont, //font
semiTransBrush2, //Brush
new PointF(xCenterOfImg+1,yPosFromBottom+1), //Position
StrFormat);
//define a Brush which is semi trasparent white (Alpha set to 153)
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
//Draw the Copyright string a second time to create a shadow effect
//Make sure to move this text 1 pixel to the right and down 1 pixel
grPhoto.DrawString(FontString, //string of text
crFont, //font
semiTransBrush, //Brush
new PointF(xCenterOfImg,yPosFromBottom), //Position
StrFormat);
imgPhoto = bmPhoto;
grPhoto.Dispose();
//save new image to file system.
imgPhoto.Save(WorkingDirectory + ImageName + "_finally.jpg", ImageFormat.Jpeg);
imgPhoto.Dispose();
//Text alignment
}
Share: Asp Chinese garbled problem solution No matter what language garbled problem exists, asp is no exception. This article will introduce the method to solve garbled code in asp. Friends who need it can refer to it.