手机
当前位置:查字典教程网 >编程开发 >ASP教程 >ASPJPEG综合操作的CLASS类
ASPJPEG综合操作的CLASS类
摘要:

<%

'ASPJPEG综合操作CLASS

ClassAspJpeg

DimAspJpeg_Obj,obj

PrivateImg_MathPath_From,Img_MathPath_To,Img_Reduce_Size,CoverIf

PrivateImg_Frame_Size,Img_Frame_Color,Img_Frame_Solid,Img_Frame_Width,Img_Frame_Height

PrivateImg_Font_Content,Img_Font_Family,Img_Font_Color,Img_Font_Quality,Img_Font_Size,Img_Font_Bold,Img_Font_X,Img_Font_Y

PrivateImg_PicIn_Path,Img_PicIn_X,Img_PicIn_Y

'--------------取原文件路径

PublicPropertyLetMathPathFrom(StrType)

Img_MathPath_From=StrType

EndProperty

'--------------取文件保存路径

PublicPropertyLetMathPathTo(strType)

Img_MathPath_To=strType

EndProperty

'--------------保存文件时是否覆盖已有文件

PublicPropertyLetCovePro(LngSize)

IfLngSize=0orLngSize=1orLngSize=trueorLngSize=falsethen

CoverIf=LngSize

EndIf

EndProperty

'---------------取缩略图/放大图缩略值

PublicPropertyLetReduceSize(LngSize)

IfisNumeric(LngSize)then

Img_Reduce_Size=LngSize

EndIf

EndProperty

'---------------取描边属性

'边框粗细

PublicPropertyLetFrameSize(LngSize)

IfisNumeric(LngSize)then

Img_Frame_Size=Clng(LngSize)

EndIf

EndProperty

'边框宽度

PublicPropertyLetFrameWidth(LngSize)

IfisNumeric(LngSize)then

Img_Frame_Width=Clng(LngSize)

EndIf

EndProperty

'边框高度

PublicPropertyLetFrameHeight(LngSize)

IfisNumeric(LngSize)then

Img_Frame_Height=Clng(LngSize)

EndIf

EndProperty

'边框颜色

PublicPropertyLetFrameColor(strType)

IfstrType<>""then

Img_Frame_Color=strType

EndIf

EndProperty

'边框是否加粗

PublicPropertyLetFrameSolid(LngSize)

IfLngSize=1orLngSize=0orLngSize=trueorLngSize=falsethen

Img_Frame_Solid=LngSize

EndIf

EndProperty

'---------------取插入文字属性

'插入的文字

PublicPropertyLetContent(strType)

IfstrType<>""then

Img_Font_Content=strType

EndIf

EndProperty

'文字字体

PublicPropertyLetFontFamily(strType)

IfstrType<>""then

Img_Font_Family=strType

EndIf

EndProperty

'文字颜色

PublicPropertyLetFontColor(strType)

IfstrType<>""then

Img_Font_Color=strType

EndIf

EndProperty

'文字品质

PublicPropertyLetFontQuality(LngSize)

IfisNumeric(LngSize)then

Img_Font_Quality=Clng(LngSize)

EndIf

EndProperty

'文字大小

PublicPropertyLetFontSize(LngSize)

IfisNumeric(LngSize)then

Img_Font_Size=Clng(LngSize)

EndIf

EndProperty

'文字是否加粗

PublicPropertyLetFontBold(LngSize)

IfLngSize=1orLngSize=0orLngSize=trueorLngSize=falsethen

Img_Font_Bold=LngSize

EndIf

EndProperty

'输入文字的X坐标

PublicPropertyLetFontX(LngSize)

IfisNumeric(LngSize)then

Img_Font_X=Clng(LngSize)

EndIf

EndProperty

'输入文字的Y坐标

PublicPropertyLetFontY(LngSize)

IfisNumeric(LngSize)then

Img_Font_Y=Clng(LngSize)

EndIf

EndProperty

'---------------取插入图片属性

'插入图片的路径

PublicPropertyLetPicInPath(strType)

Img_PicIn_Path=strType

EndProperty

'图片插入的X坐标

PublicPropertyLetPicInX(LngSize)

IfisNumeric(LngSize)then

Img_PicIn_X=Clng(LngSize)

EndIf

EndProperty

'图片插入的Y坐标

PublicPropertyLetPicInY(LngSize)

IfisNumeric(LngSize)then

Img_PicIn_Y=Clng(LngSize)

EndIf

EndProperty

PrivateSubClass_Initialize()

SetAspJpeg_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

EndSub

PrivateSubClass_Terminate()

Err.Clear

SetAspJpeg_Obj=Nothing

EndSub

'判断文件是否存在

PrivateFunctionFileIs(path)

Setfsos=Server.createObject("Scripting.FileSystemObject")

FileIs=fsos.FileExists(path)

Setfsos=Nothing

EndFunction

'判断目录是否存在

PrivateFunctionFolderIs(path)

Setfsos=Server.createObject("Scripting.FileSystemObject")

FolderIs=fsos.FolderExists(path)

Setfsos=Nothing

EndFunction

'*******************************************

'函数作用:取得当前文件的上一级路径

'*******************************************

PrivateFunctionUpDir(ByValD)

IfLen(D)=0then

UpDir=""

Else

UpDir=Left(D,InStrRev(D,"")-1)

EndIf

EndFunction

PrivateFunctionErrors(Errors_id)

selectCaseErrors_id

Case"0"

Errors="指定文件不存在"

Case1

Errors="指定目录不存在"

Case2

Errors="已存在相同名称文件"

Case3

Errors="参数溢出"

Endselect

EndFunction

'取图片宽度

PublicFunctionImgInfo_Width(Img_MathPath)

IfNot(FileIs(Img_MathPath))then

'ExitFunction

ImgInfo_Width=Errors(0)

Else

AspJpeg_Obj.OpenImg_MathPath

ImgInfo_Width=AspJpeg_Obj.width

EndIf

EndFunction

'取图片高度

PublicFunctionImgInfo_Height(Img_MathPath)

IfNot(FileIs(Img_MathPath))then

'ExitFunction

ImgInfo_Height=Errors(0)

Else

AspJpeg_Obj.OpenImg_MathPath

ImgInfo_Height=AspJpeg_Obj.height

EndIf

EndFunction

'生成缩略图/放大图

PublicFunctionImg_Reduce()

IfNot(FileIs(Img_MathPath_From))then

Img_Reduce=Errors(0)

ExitFunction

EndIf

IfNot(FolderIs(UpDir(Img_MathPath_To)))then

Img_Reduce=Errors(1)

ExitFunction

EndIf

IfCoverIf=0orCoverIf=Falsethen

IfFileIs(Img_MathPath_To)then

Img_Reduce=Errors(2)

ExitFunction

EndIf

EndIf

AspJpeg_Obj.OpenImg_MathPath_From

AspJpeg_Obj.PreserveAspectRatio=True

IfAspJpeg_Obj.OriginalWidth>AspJpeg_Obj.OriginalHeightThen

AspJpeg_Obj.Width=Img_Reduce_Size

Else

AspJpeg_Obj.Height=Img_Reduce_Size

EndIf

IfAspJpeg_Obj.OriginalWidth>Img_Reduce_SizeorAspJpeg_Obj.OriginalHeight>Img_Reduce_SizeThen

IfAspJpeg_Obj.Width<Img_Reduce_SizeorAspJpeg_Obj.Height<Img_Reduce_Sizethen

SetAspJpeg_Obj_New=createObject("Persits.Jpeg")

AspJpeg_Obj_New.newImg_Reduce_Size,Img_Reduce_Size,&HFFFFFF

AspJpeg_Obj_New.DrawImage(150-AspJpeg_Obj.width)/2,(150-AspJpeg_Obj.height)/2,AspJpeg_Obj

IfImg_Frame_Size>0then

CallImg_Pen(AspJpeg_Obj_New)

EndIf

IfImg_Font_Content<>""then

Img_Font_X=AspJpeg_Obj_New.Width/2

Img_Font_Y=AspJpeg_Obj_New.Height-15

CallImg_Font(AspJpeg_Obj_New)

EndIf

AspJpeg_Obj_New.Sharpen1,130

AspJpeg_Obj_New.SaveImg_MathPath_To

SetAspJpeg_Obj_New=Nothing

Else

IfImg_Frame_Size>0then

CallImg_Pen(AspJpeg_Obj)

EndIf

IfImg_Font_Content<>""then

Img_Font_X=AspJpeg_Obj.Width/2

Img_Font_Y=AspJpeg_Obj.Height-15

CallImg_Font(AspJpeg_Obj)

EndIf

AspJpeg_Obj.Sharpen1,130

AspJpeg_Obj.SaveImg_MathPath_To

EndIf

Else

IfImg_Frame_Size>0then

CallImg_Pen(AspJpeg_Obj)

EndIf

IfImg_Font_Content<>""then

Img_Font_X=AspJpeg_Obj.Width/2

Img_Font_Y=AspJpeg_Obj.Height-15

CallImg_Font(AspJpeg_Obj)

EndIf

AspJpeg_Obj.Sharpen1,130

AspJpeg_Obj.SaveImg_MathPath_To

EndIf

EndFunction

'生成水印

PublicFunctionImg_WaterMark()

IfNot(FileIs(Img_MathPath_From))then

Img_WaterMark=Errors(0)

ExitFunction

EndIf

IfImg_MathPath_To=""then

Img_MathPath_To=Img_MathPath_From

ElseIfNot(FolderIs(UpDir(Img_MathPath_To)))then

Img_WaterMark=Errors(1)

ExitFunction

EndIf

IfCoverIf=0orCoverIf=falsethen

IfImg_MathPath_To<>Img_MathPath_FromandFileIs(Img_MathPath_To)then

Img_WaterMark=Errors(2)

ExitFunction

EndIf

EndIf

AspJpeg_Obj.OpenImg_MathPath_From

IfImg_PicIn_Path<>""then

IfNot(FileIs(Img_PicIn_Path))then

Img_WaterMark=Errors(0)

ExitFunction

EndIf

SetAspJpeg_Obj_New=createObject("Persits.Jpeg")

AspJpeg_Obj_New.OpenImg_PicIn_Path

AspJpeg_Obj.PreserveAspectRatio=True

AspJpeg_Obj_New.PreserveAspectRatio=True

IfAspJpeg_Obj.OriginalWidth<Img_Reduce_SizeorAspJpeg_Obj.OriginalHeight<Img_Reduce_Sizethen

Img_WaterMark=Errors(3)

ExitFunction

EndIf

IfAspJpeg_Obj_New.OriginalWidth>AspJpeg_Obj_New.OriginalHeightThen

AspJpeg_Obj_New.Width=Img_Reduce_Size

Else

AspJpeg_Obj_New.Height=Img_Reduce_Size

EndIf

IfImg_PicIn_X=""thenImg_PicIn_X=AspJpeg_Obj.Width-AspJpeg_Obj_New.Width

IfImg_PicIn_Y=""thenImg_PicIn_Y=AspJpeg_Obj.Height-AspJpeg_Obj_New.Height

AspJpeg_Obj.DrawImageImg_PicIn_X,Img_PicIn_Y,AspJpeg_Obj_New

SetAspJpeg_Obj_New=Nothing

EndIf

IfImg_Frame_Size>0then

CallImg_Pen(AspJpeg_Obj)

EndIf

IfImg_Font_Content<>""then

CallImg_Font(AspJpeg_Obj)

EndIf

'AspJpeg_Obj.Sharpen1,130

AspJpeg_Obj.SaveImg_MathPath_To

EndFunction

'生成框架

PrivateFunctionImg_Pen(Obj)

IfImg_Frame_Width=0thenImg_Frame_Width=Obj.Width

IfImg_Frame_Height=0thenImg_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.Bar1,1,Img_Frame_Width,Img_Frame_Height

EndFunction

'生成水印字

PrivateFunctionImg_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.PrintImg_Font_X,Img_Font_Y,Img_Font_Content

EndFunction

EndClass

%>

这个类可以公开调用

1.ImgInfo_Height取图片高度

2.ImgInfo_Width取图片宽度

调用方法:

复制代码 代码如下:

DimNewObj,Pic_h,Pic_w

SetNewObj=NewAspJpeg

Pic_h=NewObj.ImgInfo_Height("f:/test.jpg")

Pic_w=NewObj.ImgInfo_Width("f:/test.jpg")

SetNewObj=Nothing

Response.Write"ThisPicture'sHeightis"&Pic_h

Response.Write"ThisPicture'sWidthis"&Pic_w

Response.End

3.Img_Reduce对指定图片缩小或放大并保存(可选择是否加水印,是否加框架)

必须定义声明MathPathFrom,MathPathTo

默认为缩放至150X150图案如按比例缩放后图案小于该尺寸,则补充空白图片

默认文件自动覆盖

实例:

复制代码 代码如下:

DimNewObj,NewCommand

SetNewObj=NewAspJpeg

NewObj.MathPathFrom="f:/test.jpg"

NewObj.MathPathTo="f:/reduce.jpg"

NewCommand=NewObj.Img_Reduce

SetNewObj=Nothing

IfNewCommand<>""then

Response.Write"Success"

Else

'图片操作过程中出现错误

Response.Write"Failed"

EndIf

4.Img_WaterMark给指定图片添加水印

水印可以为图片文字或2者结合

【ASPJPEG综合操作的CLASS类】相关文章:

ASP中经常使用的SQL语句与教程说明

ASP中字符与数字操作函数总结

ASP中FCKEditor编辑器的设置教程

ASP用户注册功能的实现

CJJ专用ASP类库中的某个class

域名查询系统用到的类

用ASP实现hashMap功能的类

ASP通用模板类

用ASP做的DNS LOOKUP程序

FSO操作文件系统

精品推荐
分类导航