ASP component AspJpeg (watermark) generate thumbnails and other usage methods

Source: Internet
Author: User
Tags watermark images

ASP component AspJpeg (watermark) generate thumbnails and other usage methods

Font: [Increase decrease] Type: Reprint time: 2012-12-17 I want to comment

AspJpeg is a fairly powerful image processing component that makes it easy to make thumbnails of images and watermark images. Here is a brief introduction to the use of methods, the need for friends to understand the next

first, to add a watermark to the picture

Copy CodeThe code is as follows:
<%
Dim Jpeg '//DECLARE 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 = "Arial" "//Watermark Font
Jpeg.Canvas.Font.Size = 14 "'//Watermark font Size
Jpeg.Canvas.Font.Bold = False "//Is bold, bold: True
Jpeg.Canvas.Font.BkMode = &hffffff "'//font background color
Jpeg.Canvas.Print 10, 10, "Invincible Urchin Studio" "'//Watermark text, two digits 10 for watermark XY coordinates
Jpeg.save Server.MapPath ("aaa_05.jpg") "//Generate new picture with watermark and save location
Set Jpeg = Nothing "'//Unregister component, release resources
Response.Write "%>


ASP picture Watermark AspJpeg v1.8 Special Edition
second, generate thumbnail image

Copy CodeThe code is as follows:
<%
Dim Jpeg '//DECLARE variable
Set Jpeg = Server.CreateObject ("Persits.jpeg") ""//Calling Component
Jpeg.open Server.MapPath ("AAA. JPG ") '//Original location
Jpeg.width = JPEG.ORIGINALWIDTH/4 "//Set image width to One-fourth of the original
Jpeg.height = JPEG.ORIGINALHEIGHT/4 "//Set the image height to One-fourth of the original
Jpeg.sharpen 1, 130 "//Set Sharpening effect
Jpeg.save Server.MapPath ("aaa_small.jpg") ""//Generate thumbnail position and name
Set Jpeg = Nothing "'//Unregister component, release resources
Response.Write "%>


Introduction to advanced usage methods for ASPJPEG components
AspJpeg is a very powerful image processing component in English only. However, there have been free version and cracked version, but the detailed and in-depth introduction of the article is not much, even if there is also only the image thumbnail and image watermark. Maybe it's because of pure English.
Here I am talking about the advanced usage of aspjpeg for these questions. The technology here mainly includes:
Picture thumbnails
Image watermark
Security Code Technology
Picture Cutting
Picture Merge
Database support
more less common ways to introduce
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 the output method. In addition, I am more lazy, so some code is still quoted in the original document, do not know where I will explain!
A comrade who has studied VB or. NET must have seen it. Brush again. Oh.
First, picture thumbnail

Copy CodeThe code is as follows:
<%
Set Jpeg = Server.CreateObject ("persits.jpeg") call component
Path = Server.MapPath ("Images") & "\clock.jpg" Pending picture paths
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, the picture watermark

Copy CodeThe code is 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 if bold
Jpeg.Canvas.Print, "Copyright (c) XYZ, Inc."
Print coordinates x print coordinates y characters that need to be printed
The following is a border processing of a picture
Jpeg.Canvas.Pen.Color = &h000000 "Black color
Jpeg.Canvas.Pen.Width = 2 Brush width
Jpeg.Canvas.Brush.Solid = False whether 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
Safety of the truth and watermark almost, many friends asked me to specific code technology, here I write to share with you, the General people I still do not tell him. Oh.

Copy CodeThe code is as follows:
<%
The function of generating security code www.wuyouw.com
function Make_randomize (max_len,w_n) max_len generation length, w_n:0 may contain letters, 1: Numbers only
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 have to prepare a background map beforehand.

Copy CodeThe code is as follows:
<%random_num=make_randomize (4,1) generates a 4-digit security Code
Session ("Random_num") =random_num why call session, no session security code is completely meaningless. Oh
Set Jpeg = Server.CreateObject ("persits.jpeg") call 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 the upper-left corner x-coordinate, y-coordinate x-coordinate y-coordinate of the lower-right corner
I'm going to do a demo, 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
How's that, easy?

Five, picture merger
We're here to add the logo image to the dodge_viper.jpg picture.
In fact, the method of image merging can also be used for dynamic water printing OH

Copy CodeThe code is 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


The output method of Sendbinary is used here. Of course, you can also save the changed dodge_viper.jpg first, and then enter it. I personally do not like to use the Sendbinary method, in the slow speed when the error prone. Not much in terms of speed. Oh.
Vi. Database Support
There's not much to say here. In fact, is the binary method, you know that the picture stored in the database can only be saved as binary files. So the code is lazy to write.

Seven, more methods introduction
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 a code that describes the
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, we are talking about ASP to the picture watermark knowledge
ASP to image watermark is required components ... Commonly used have aspjpeg and the Chinese self-developed wsimage ... The former has 30 days of free ... The latter is completely free ... Of course we have to use the Chinese products. Hey..
methods for registering components:
At the command prompt, enter "regsvr32 [DLL path]".
Image watermark is simply to get the image size, and then write the watermark up. ASP code is just a control component. Use the code to explain everything.

One: Get the picture size(This is represented by a pixel value.) A friend who learns Photoshop should understand it.

Copy CodeThe code is as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize") "" "Call component
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "Open the picture, the image name is 25.jpg
Obj. Getsourceinfo Iwidth,iheight
Response.Write "Picture width:" & iwidth & "<br>" "" to get the width of the picture
Response.Write "Image height:" & iheight & "<br>" "" to 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 CodeThe code is as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "Load picture
Obj. Quality=75
Obj. Txtmarkfont = "Chinese Colorful Cloud" "" "Set watermark text font
Obj. Txtmarkbond = False "" To set the thickness of the watermark text
Obj. markrotate = 0 "" "the angle of rotation of the watermark text
Obj. Txtmarkheight = 25 "" The height of the watermark text
Obj. Addtxtmark Server.MapPath ("txtmark.jpg"), "take you to the departure", &h00ff00&, 10, 70
Strerror=obj.errorinfo "" Generates the image name, the text color is the watermark in the picture position
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>


Three: Add picture watermark

Copy CodeThe code is as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "Load picture
Obj. Loadimgmarkpic Server.MapPath ("blend.bmp") "" "Load watermark Picture
Obj. Quality=75
Obj. Addimgmark Server.MapPath ("imgmark.jpg"), 315, 220,&AMP;HFFFFFF, 70
Strerror=obj.errorinfo "" Generates the image name, the text color is the watermark in the picture position
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>


In fact, it's so easy to add a watermark to a picture. And then I'm going to say another two main uses of the WsImage.dll component. Include:
Crop the picture to create a thumbnail image of the picture.

Or in my habit, with the Code annotated description:
To crop a picture :

Copy CodeThe code is 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 "" "Defines the cut size and generates the picture name
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>


Detailed comment: Cut the picture to use the Wsimage Cropimage method. Where the image is created, the 100,10 is the cut point in the upper-left corner, which is 100 pixels from 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 create a thumbnail image:

Copy CodeThe code is 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 export a thumbnail image :
(1) obj. Outputspic Server.MapPath ("25_s.jpg"), 200,150,0
200 is the output width, 150 is the output high, this output form is the force output width high, may cause the picture distortion.
(2) obj. Outputspic Server.MapPath ("25_s.jpg"), 200,0,1
With a output width of 200, the output height will scale with the column.
(3) obj. Outputspic Server.MapPath ("25_s.jpg"), 0,200,2
The output is high at 200 and the output width is scaled with the ratio 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 wide scale reduction.
The second 0.5 indicates that the generated thumbnail is half the height of the original image, which means a high zoom out ratio.
A consistent reduction in the width and height means that the original image will be scaled down. If the zoom ratio is greater than 1, the original image is enlarged.
Transferred from: http://hi.baidu.com/miracle521/blog/item/e3419133fdc00746ac4b5f25.html
2-----------------------------------------------------------------------------------
ASP. Upload image watermark (text watermark, image watermark, text + image watermark)
Images and watermarks (text watermark, image watermark, text + image watermark)


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

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

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

Code:
DrawImg.cs

Copy CodeThe code is 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}; Enumeration 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//Sets the watermark picture, the description is to watermark the image effect
{
Dealtype = Dealtype.waterimage;
Imagewater = value;
}
}
public string publicfontstring
{
Get
{
return fontstring;
}
Set//sets the watermark text to be a 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 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 arrays of 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
If its length in pixles are 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 would have varying heights, determine a
Position 5% from the bottom of the image
int ypixlesfrombottom = (int) (Phheight *.05);
Now, 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
}

ASP component AspJpeg (watermark) generate thumbnails and other usage methods

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.