Class class _asp classes for ASPJPEG integrated operations

Source: Internet
Author: User
Tags border color
<%
' AspJpeg Integrated Operation class
Class AspJpeg
Dim Aspjpeg_obj,obj
Private Img_mathpath_from,img_mathpath_to,img_reduce_size,coverif
Private Img_frame_size,img_frame_color,img_frame_solid,img_frame_width,img_frame_height
Private img_font_content,img_font_family,img_font_color,img_font_quality,img_font_size,img_font_bold,img_font_x , img_font_y
Private img_picin_path,img_picin_x,img_picin_y
'--------------take the original file path
Public Property Let Mathpathfrom (Strtype)
Img_mathpath_from=strtype
End Property

'--------------File Save path
Public Property Let Mathpathto (Strtype)
Img_mathpath_to=strtype
End Property

'--------------whether to overwrite existing files when saving files
Public Property Let Covepro (Lngsize)
If lngsize=0 or lngsize=1 or lngsize=true or Lngsize=false then
Coverif=lngsize
End If
End Property

'---------------thumbnail/magnification thumbnail
Public Property Let Reducesize (Lngsize)
If IsNumeric (lngsize) Then
Img_reduce_size=lngsize
End If
End Property

'---------------Stroke Property
' Border thickness
Public Property Let Framesize (Lngsize)
If IsNumeric (lngsize) Then
IMG_FRAME_SIZE=CLNG (Lngsize)
End If
End Property
' Border width
Public Property Let Framewidth (Lngsize)
If IsNumeric (lngsize) Then
IMG_FRAME_WIDTH=CLNG (Lngsize)
End If
End Property
' Border height
Public Property Let Frameheight (Lngsize)
If IsNumeric (lngsize) Then
IMG_FRAME_HEIGHT=CLNG (Lngsize)
End If
End Property
' Border color
Public Property Let FrameColor (Strtype)
If strtype<> "" Then
Img_frame_color=strtype
End If
End Property
' Border is bold
Public Property Let Framesolid (Lngsize)
If lngsize=1 or lngsize=0 or lngsize=true or Lngsize=false then
Img_frame_solid=lngsize
End If
End Property

'---------------Insert Text property
' Inserted text
Public Property Let Content (Strtype)
If strtype<> "" Then
Img_font_content=strtype
End If
End Property
' Text font
Public Property Let FontFamily (Strtype)
If strtype<> "" Then
Img_font_family=strtype
End If
End Property
' Text color
Public Property Let FontColor (Strtype)
If strtype<> "" Then
Img_font_color=strtype
End If
End Property
' Text quality
Public Property Let Fontquality (Lngsize)
If IsNumeric (lngsize) Then
IMG_FONT_QUALITY=CLNG (Lngsize)
End If
End Property
' Text size
Public Property Let FontSize (Lngsize)
If IsNumeric (lngsize) Then
IMG_FONT_SIZE=CLNG (Lngsize)
End If
End Property
' Whether the text is bold
Public Property Let FontBold (Lngsize)
If lngsize=1 or lngsize=0 or lngsize=true or Lngsize=false then
Img_font_bold=lngsize
End If
End Property
' Enter the X coordinate of the text
Public Property Let FontX (Lngsize)
If IsNumeric (lngsize) Then
IMG_FONT_X=CLNG (Lngsize)
End If
End Property
' Enter the y-coordinate of the text
Public Property Let Fonty (Lngsize)
If IsNumeric (lngsize) Then
IMG_FONT_Y=CLNG (Lngsize)
End If
End Property

'---------------Insert Picture Properties
' Insert the path of the picture
Public Property Let Picinpath (Strtype)
Img_picin_path=strtype
End Property
' x coordinates for picture insertion
Public Property Let Picinx (Lngsize)
If IsNumeric (lngsize) Then
IMG_PICIN_X=CLNG (Lngsize)
End If
End Property
' The y-coordinate of the picture insert
Public Property Let Piciny (Lngsize)
If IsNumeric (lngsize) Then
IMG_PICIN_Y=CLNG (Lngsize)
End If
End Property


Private Sub Class_Initialize ()
Set aspjpeg_obj=createobject ("Persits.jpeg")
Img_mathpath_from= ""
Img_mathpath_to= ""
img_reduce_size=150
Img_frame_size=1
' Img_frame_width=0
' Img_frame_height=0
' Img_frame_color= ' &h000000 '
' Img_frame_bold=false
Img_font_content= "Goldenleaf"
' Img_font_family= ' Arial.
' Img_font_color= ' &h000000 '
Img_font_quality=3
Img_font_size=14
' Img_font_bold=false
img_font_x=10
Img_font_y=5
' Img_picin_x=0
' Img_picin_y=0
Coverif=1

End Sub
Private Sub Class_Terminate ()
Err.Clear
Set aspjpeg_obj=nothing
End Sub
' To determine if a file exists
Private Function Fileis (path)
Set fsos=server.createobject ("Scripting.FileSystemObject")
Fileis=fsos. FileExists (PATH)
Set fsos=nothing
End Function

' Determine if the directory exists
Private Function Folderis (path)
Set fsos=server.createobject ("Scripting.FileSystemObject")
Folderis=fsos. FolderExists (PATH)
Set fsos=nothing
End Function
'*******************************************
' Function: Get the previous path to the current file
'*******************************************
Private Function Updir (ByVal D)
If Len (D) = 0 Then
Updir= ""
Else
Updir=left (D,instrrev (D, "\")-1)
End If
End Function

Private Function Errors (errors_id)
Select Case errors_id
Case "0"
Errors= "Specifies that the file does not exist"
Case 1
errors= "specified directory does not exist"
Case 2
errors= "Same name file already exists"
Case 3
errors= "Parameter Overflow"
End Select
End Function


' Take picture width
Public Function imginfo_width (Img_mathpath)
If Not (Fileis (Img_mathpath)) Then
' Exit Function
Imginfo_width=errors (0)
Else
Aspjpeg_obj.open Img_mathpath
Imginfo_width=aspjpeg_obj.width
End If
End Function
' Take picture height
Public Function imginfo_height (Img_mathpath)
If Not (Fileis (Img_mathpath)) Then
' Exit Function
Imginfo_height=errors (0)
Else
Aspjpeg_obj.open Img_mathpath
Imginfo_height=aspjpeg_obj.height
End If
End Function
' Generate thumbnails/enlarge the graph
Public Function Img_reduce ()
If Not (Fileis (img_mathpath_from)) Then
Img_reduce=errors (0)
Exit Function
End If
If Not (Folderis (Updir (img_mathpath_to)) Then
Img_reduce=errors (1)
Exit Function
End If
If coverif=0 or Coverif=false Then
If Fileis (img_mathpath_to) Then
Img_reduce=errors (2)
Exit Function
End If
End If
Aspjpeg_obj.open Img_mathpath_from
Aspjpeg_obj.preserveaspectratio = True
If Aspjpeg_obj.originalwidth>aspjpeg_obj.originalheight Then
Aspjpeg_obj.width=img_reduce_size
Else
Aspjpeg_obj.height=img_reduce_size
End If
If aspjpeg_obj.originalwidth>img_reduce_size or Aspjpeg_obj.originalheight>img_reduce_size Then
If aspjpeg_obj.widthSet aspjpeg_obj_new=createobject ("Persits.jpeg")
Aspjpeg_obj_new.new IMG_REDUCE_SIZE,IMG_REDUCE_SIZE,&AMP;HFFFFFF
Aspjpeg_obj_new.drawimage (150-aspjpeg_obj.width)/2, (150-aspjpeg_obj.height)/2,aspjpeg_obj
If Img_frame_size>0 Then
Call Img_pen (aspjpeg_obj_new)
End If
If img_font_content<> "" Then
Img_font_x=aspjpeg_obj_new.width/2
Img_font_y=aspjpeg_obj_new.height-15
Call Img_font (aspjpeg_obj_new)
End If
Aspjpeg_obj_new.sharpen 1, 130
Aspjpeg_obj_new.save img_mathpath_to
Set aspjpeg_obj_new=nothing
Else
If Img_frame_size>0 Then
Call Img_pen (Aspjpeg_obj)
End If
If img_font_content<> "" Then
Img_font_x=aspjpeg_obj.width/2
Img_font_y=aspjpeg_obj.height-15
Call Img_font (Aspjpeg_obj)
End If
Aspjpeg_obj.sharpen 1, 130
Aspjpeg_obj.save img_mathpath_to
End If
Else
If Img_frame_size>0 Then
Call Img_pen (Aspjpeg_obj)
End If
If img_font_content<> "" Then
Img_font_x=aspjpeg_obj.width/2
Img_font_y=aspjpeg_obj.height-15
Call Img_font (Aspjpeg_obj)
End If
Aspjpeg_obj.sharpen 1, 130
Aspjpeg_obj.save img_mathpath_to
End If
End Function
' Generate watermarks
Public Function Img_watermark ()
If Not (Fileis (img_mathpath_from)) Then
Img_watermark=errors (0)
Exit Function
End If
If img_mathpath_to= "" Then
Img_mathpath_to=img_mathpath_from
ElseIf Not (Folderis (Updir (img_mathpath_to)) Then
Img_watermark=errors (1)
Exit Function
End If
If coverif=0 or Coverif=false Then
If Img_mathpath_to<>img_mathpath_from and Fileis (img_mathpath_to) Then
Img_watermark=errors (2)
Exit Function
End If
End If
Aspjpeg_obj.open Img_mathpath_from
If img_picin_path<> "" Then
If Not (Fileis (Img_picin_path)) Then
Img_watermark=errors (0)
Exit Function
End If
Set aspjpeg_obj_new=createobject ("Persits.jpeg")
Aspjpeg_obj_new.open Img_picin_path
Aspjpeg_obj.preserveaspectratio = True
Aspjpeg_obj_new.preserveaspectratio = True
If aspjpeg_obj.originalwidthImg_watermark=errors (3)
Exit Function
End If
If Aspjpeg_obj_new.originalwidth>aspjpeg_obj_new.originalheight Then
Aspjpeg_obj_new.width=img_reduce_size
Else
Aspjpeg_obj_new.height=img_reduce_size
End If
If img_picin_x= "" Then Img_picin_x=aspjpeg_obj.width-aspjpeg_obj_new.width
If img_picin_y= "" Then Img_picin_y=aspjpeg_obj.height-aspjpeg_obj_new.height
Aspjpeg_obj.drawimage img_picin_x,img_picin_y,aspjpeg_obj_new
Set aspjpeg_obj_new=nothing
End If
If Img_frame_size>0 Then
Call Img_pen (Aspjpeg_obj)
End If
If img_font_content<> "" Then
Call Img_font (Aspjpeg_obj)
End If
' Aspjpeg_obj.sharpen 1, 130
Aspjpeg_obj.save img_mathpath_to
End Function
' Build framework
Private Function Img_pen (OBJ)
If Img_frame_width=0 then Img_frame_width=obj.width
If Img_frame_height=0 then Img_frame_height=obj.height
Obj.Canvas.Pen.Color = Img_frame_color
Obj.Canvas.Pen.Width = Img_frame_size
Obj.Canvas.Brush.Solid = Img_frame_solid
Obj.Canvas.Bar 1,1,img_frame_width,img_frame_height
End Function
' Generate watermark Word
Private Function Img_font (OBJ)
Obj.Canvas.Font.Color = Img_font_color
Obj.Canvas.Font.Family = img_font_family
Obj.canvas.font.quality=img_font_quality
Obj.canvas.font.size=img_font_size
Obj.Canvas.Font.Bold = Img_font_bold
Obj.Canvas.Print img_font_x,img_font_y,img_font_content
End Function
End Class
%>
This class can be called publicly
1. imginfo_height Take picture height
2. imginfo_width Take picture width
Call Method:
Copy Code code as follows:

Dim Newobj,pic_h,pic_w
Set newobj=new AspJpeg
Pic_h=newobj.imginfo_height ("F:/test.jpg")
Pic_w=newobj.imginfo_width ("F:/test.jpg")
Set newobj=nothing
Response.Write "This picture ' s" &pic_h
Response.Write "This picture ' s" &pic_w
Response.End

3. Img_reduce the specified picture to reduce or enlarge and save (you can choose whether to add watermark, whether the frame)
Declaration Mathpathfrom,mathpathto must be defined
Default to zoom to 150x150 pattern if the pattern is smaller than the size after scaling, the blank picture is added
Default File Auto Overwrite
Instance:
Copy Code code as follows:

Dim Newobj,newcommand
Set newobj=new AspJpeg
Newobj.mathpathfrom= "F:/test.jpg"
Newobj.mathpathto= "F:/reduce.jpg"
Newcommand=newobj.img_reduce
Set newobj=nothing
If newcommand<> "" Then
Response.Write "Success"
Else
' Error occurred during picture operation
Response.Write "Failed"
End If

4. Img_watermark to add a watermark to the specified picture
Watermarks can be combined for picture text or 2

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.