ASP component AspJpeg (watermark) to generate thumbnails, such as the use of methods _ application techniques

Source: Internet
Author: User
Tags trim
Add a watermark to a picture
Copy Code code as follows:

<%
Dim Jpeg ' '//Declaration variable
Set Jpeg = Server.CreateObject ("persits.jpeg") '//Calling Component
Jpeg.open Server.MapPath ("AAA"). JPG ")"//Source Picture location
Jpeg.Canvas.Font.Color = &h000000 ' '/watermark font Color
Jpeg.Canvas.Font.Family = "Song Body" '/watermark Font
Jpeg.Canvas.Font.Size = 14 '//Watermark font Size
Jpeg.Canvas.Font.Bold = False '//Bold, Bold: True
Jpeg.Canvas.Font.BkMode = &hffffff ' '//font background color
Jpeg.Canvas.Print 10, 10, "unbeaten studio" '//Watermark text, two digit 10 xy coordinates for Watermark
Jpeg.save Server.MapPath ("aaa_05.jpg") '//Create new image with watermark and save location
Set Jpeg = Nothing ' '//Logoff component, releasing resources
Response.Write "%>

ASP image Watermark AspJpeg v1.8 Special Edition
second, generate thumbnails
Copy Code code as follows:

<%
Dim Jpeg ' '//Declaration variable
Set Jpeg = Server.CreateObject ("persits.jpeg") '//Calling Component
Jpeg.open Server.MapPath ("AAA"). JPG ")" '//Original position
Jpeg.width = Jpeg.originalwidth/4 '//Set picture width to One-fourth of original image
Jpeg.height = JPEG.ORIGINALHEIGHT/4 '//Set picture height to One-fourth of original image
Jpeg.sharpen 1, 130 "'/Set Sharpening effect
Jpeg.save Server.MapPath ("aaa_small.jpg") '//Generate thumbnail location and name
Set Jpeg = Nothing ' '//Logoff component, releasing resources
Response.Write "%>

Introduction to advanced usage of ASPJPEG components
AspJpeg is a very powerful image processing component, a pure English version. However, there has been a free version and cracked version, but the detailed and in-depth introduction of the article is not much, even if there is only a picture of the thumbnail and image watermark. Maybe it's because of pure English.
This is where I talk about the advanced usage of aspjpeg. The main technologies here include:
Thumbnail image
Picture watermark
Security Code Technology
Picture Cutting
Picture Merge
Database support
more less frequently used method introduction
And some of the relevant practical techniques
AspJpeg the only point is that the output mode is relatively single. Here, we mainly talk about how to save the image processing and then call this output method. In addition, I am lazy, so some code is still quoted in the original file, do not understand the place I will explain!
The comrade who has studied VB or. NET must see it clearly. Brush again. Oh.
One, the picture is abbreviated
Copy Code code as follows:

<%
Set Jpeg = Server.CreateObject ("Persits.jpeg") Invoke component
Path = Server.MapPath ("Images") & "\clock.jpg" Picture path to process
Jpeg.open Path Open Picture
High and wide for the original picture of 1/2
Jpeg.width = JPEG.ORIGINALWIDTH/2
Jpeg.height = JPEG.ORIGINALHEIGHT/2
Save picture
Jpeg.save Server.MapPath ("Images") & "\clock_small.jpg"
%>

View processed Pictures
second, picture Watermark
Copy Code code as follows:

<%
Set Jpeg = Server.CreateObject ("Persits.jpeg")
Jpeg.open Server.MapPath ("Images/dodge_viper.jpg")
Start writing text
Jpeg.Canvas.Font.Color = &h000000 ' white color
Jpeg.Canvas.Font.Family = "Courier New" font
Jpeg.Canvas.Font.Bold = True is bold
Jpeg.Canvas.Print, "Copyright (c) XYZ, Inc."
Print coordinates x print coordinates y the characters you need to print
The following is a border treatment of a picture
Jpeg.Canvas.Pen.Color = &h000000 ' Black color
Jpeg.Canvas.Pen.Width = 2 Brush width
Jpeg.Canvas.Brush.Solid = False is bold processing
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
%>

third, security code
Safe Ma Truth and add watermark almost, a lot of friends asked me to specific code technology, here I write to share with you, ordinary people I do not tell him. Oh.
Copy Code code as follows:

<%
function www.wuyouw.com to generate security code
function Make_randomize (max_len,w_n) Max_len build 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
%>

A picture that generates a security code. Of course, you have to prepare a background picture beforehand.
Copy Code code as follows:

<%random_num=make_randomize (4,1) generates a 4-digit security Code
Session ("Random_num") =random_num why call session, no session of the security code is completely meaningless. Oh
Set Jpeg = Server.CreateObject ("Persits.jpeg") Invoke 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
%>


Do it yourself. Oh.
Four, picture cutting
For a long time, people who don't know aspjpeg think they can't use it for cutting.
In fact there is such a method of
Crop X1,y1,x2,y2
Cut rectangular type upper left corner x coordinate, y coordinate x coordinate y coordinate
I'm going to do a demo right now, huh?
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
Well, it's easy.

v. Picture merging
We're here to add the logo picture to the dodge_viper.jpg picture.
In fact, the image of the combination of methods can also be used to dynamic water printing OH
Copy Code code as follows:

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 Sendbinary output method. Of course, you can also save the changed dodge_viper.jpg first, and then enter it. I personally do not like using the Sendbinary method, when the speed is slow, error prone. Not so in terms of speed. Oh.
Vi. Database Support
There's not much to say here. In fact, is the binary method, we know that the image stored in the database can only be stored as binary files. So the code is lazy to write.

Vii. More ways of introducing
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 code that describes the
Canvas.Font.ShadowColor
Text Shadow Color
Canvas.Font.ShadowXOffset as Long
Shadow X coordinate set
Canvas.Font.ShadowYOffset as Long
Y-coordinate setting
Canvas.Font.BkMode as String
Text background
========================================
Today, we are talking about the ASP to the picture watermark knowledge
ASP to add watermark to the image is the need for components ... Commonly used by AspJpeg and the Chinese developed their own wsimage ... The former has 30 days of free ... The latter is completely free ... Of course we have to use the products of our countrymen. Hey..
ways to register a component:
At the command prompt, enter "regsvr32 [DLL path]".
Image add watermark is simply to get the picture size, and then write the watermark up. The ASP code is just a control component. Use code to explain everything.

One: Get picture size(This is represented by a pixel value.) A friend who learns Photoshop should understand.
Copy Code code as follows:

<%
Set Obj=server. CreateObject ("Wsimage.resize") "'" ' calls component
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "Open the picture, the picture name is 25.jpg
Obj. Getsourceinfo Iwidth,iheight
Response.Write "Picture width:" & iwidth & "<br>" "" to get picture width
Response.Write "Picture height:" & iheight & "<br>" "' Get picture height
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>

Two: Add text watermark
Copy Code code as follows:

<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "' Loading picture
Obj. Quality=75
Obj. Txtmarkfont = "XXFarEastFont-Arial" "'" ' Set watermark text font
Obj. Txtmarkbond = False ' "' sets the thickness of the watermark text
Obj. markrotate = 0 ' ' ' "'" ' the rotation angle of the watermark text
Obj. Txtmarkheight = 25 ' ' ' "' watermark height of text
Obj. Addtxtmark Server.MapPath ("txtmark.jpg"), "take you out of the departure", &h00ff00& 10, 70
Strerror=obj.errorinfo ' "' produces the name of the picture, the text color is the position of the watermark in the picture
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>

Three: Add a picture watermark
Copy Code code as follows:

<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "' Loading picture
Obj. Loadimgmarkpic Server.MapPath ("blend.bmp") "" "" "" ' Load watermark Picture
Obj. Quality=75
Obj. Addimgmark Server.MapPath ("imgmark.jpg"), 315, 220,&HFFFFFF, 70
Strerror=obj.errorinfo ' "' produces the name of the picture, the text color is the position of the watermark in the picture
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>

In fact, add a watermark to the picture is so simple. And then I'm going to say another two main usages of the WsImage.dll component. Includes:
Trim the picture and generate a thumbnail of the picture.

Or in my habit, use code to add notes:
Trim Picture:
Copy Code code as follows:

<%
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 cut size and generate picture name
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>

Detailed note: Cut the picture to use the Wsimage Cropimage method. When the definition generates the picture, 100,10 is the cut point in the upper left corner, which is 100 pixels to the left of the picture, and the top 10 pixels. The latter two 200 represent the cut of the broadband and high and height.
To generate a thumbnail image of a picture:
Copy Code code as follows:

<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "'" ' Load picture
Obj. Quality=75
Obj. Outputspic Server.MapPath ("25_s.jpg"), 0.5,0.5,3 "'", defines the name of the thumbnail as the size
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>

Detailed Description:
There are four ways to produce thumbnails
(1) obj. Outputspic Server.MapPath ("25_s.jpg"), 200,150,0
200 for the output width, 150 for the output is high, this type of output is forced output width high, may cause picture distortion.
(2) obj. Outputspic Server.MapPath ("25_s.jpg"), 200,0,1
With 200 as the output width, the output height will scale with the column.
(3) obj. Outputspic Server.MapPath ("25_s.jpg"), 0,200,2
Output is high with 200, and the output width will scale with the column.
(4) obj. Outputspic Server.MapPath ("25_s.jpg"), 0.5,0.5,3
The first 0.5 indicates that the resulting thumbnail is half the width of the original image, which means a narrowing ratio.
The second 0.5 means that the resulting thumbnail is half the height of the original image, which means a high narrowing ratio.
A wide-height narrowing of the proportions means that the original image will be scaled down. If the zoom ratio is greater than 1, the original image is magnified.
Turn from: http://hi.baidu.com/miracle521/blog/item/e3419133fdc00746ac4b5f25.html
2-----------------------------------------------------------------------------------
asp.net upload image watermark (text watermark, image watermark, text + image watermark)
Image watermark (text watermark, image watermark, text + image watermark)
Effect Chart:

Figure ) this.width=500 "border=0<

Watermark ) this.width=500 "border=0<

Add a watermark to the picture (note the top right corner + just below)
) this.width=500 "border=0<

Code:
DrawImg.cs
Copy Code code as follows:

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; Processed pictures
private string imagewater = String. Empty; Watermark Picture
private string fontstring = String. Empty; Watermark Text

Enum Dealtype{none,waterimage,waterfont,doubledo}; Enumerate commands
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//sets the watermark picture words are to watermark the effect of the image
{
Dealtype = Dealtype.waterimage;
Imagewater = value;
}
}
public string publicfontstring
{
Get
{
return fontstring;
}
Set//Set Watermark text description is to watermark text effect
{
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 the 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'll
Test multiple Font sizes to determine the largest posible
Font we can use for the width of the photograph
Define an array of "point sizes" you would like to consider as Possiblities
//-------------------------------------------------------
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
The If it length in pixles be 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'll have varying heights, determine a
Position 5% from the bottom of the image
int ypixlesfrombottom = (int) (Phheight *.05);
Now, we have a point size with 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
}
Related Article

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.