用户登录
用户注册

分享至

ASPJPEG综合操作的CLASS类

  • 作者: 嘉言懿行还要阳光
  • 来源: 51数据库
  • 2021-10-06
<% 
'aspjpeg综合操作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 
'--------------取原文件路径 
public property let mathpathfrom(strtype) 
img_mathpath_from=strtype 
end property 

'--------------取文件保存路径 
public property let mathpathto(strtype) 
img_mathpath_to=strtype 
end property 

'--------------保存文件时是否覆盖已有文件 
public property let covepro(lngsize) 
if lngsize=0 or lngsize=1 or lngsize=true or lngsize=false then 
coverif=lngsize 
end if 
end property 

'---------------取缩略图/放大图 缩略值 
public property let reducesize(lngsize) 
if isnumeric(lngsize) then 
img_reduce_size=lngsize 
end if 
end property 

'---------------取描边属性 
'边框粗细 
public property let framesize(lngsize) 
if isnumeric(lngsize) then 
img_frame_size=clng(lngsize) 
end if 
end property 
'边框宽度 
public property let framewidth(lngsize) 
if isnumeric(lngsize) then 
img_frame_width=clng(lngsize) 
end if 
end property 
'边框高度 
public property let frameheight(lngsize) 
if isnumeric(lngsize) then 
img_frame_height=clng(lngsize) 
end if 
end property 
'边框颜色 
public property let framecolor(strtype) 
if strtype<>"" then 
img_frame_color=strtype 
end if 
end property 
'边框是否加粗 
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 

'---------------取插入文字属性 
'插入的文字 
public property let content(strtype) 
if strtype<>"" then 
img_font_content=strtype 
end if 
end property 
'文字字体 
public property let fontfamily(strtype) 
if strtype<>"" then 
img_font_family=strtype 
end if 
end property 
'文字颜色 
public property let fontcolor(strtype) 
if strtype<>"" then 
img_font_color=strtype 
end if 
end property 
'文字品质 
public property let fontquality(lngsize) 
if isnumeric(lngsize) then 
img_font_quality=clng(lngsize) 
end if 
end property 
'文字大小 
public property let fontsize(lngsize) 
if isnumeric(lngsize) then 
img_font_size=clng(lngsize) 
end if 
end property 
'文字是否加粗 
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 
'输入文字的x坐标 
public property let fontx(lngsize) 
if isnumeric(lngsize) then 
img_font_x=clng(lngsize) 
end if 
end property 
'输入文字的y坐标 
public property let fonty(lngsize) 
if isnumeric(lngsize) then 
img_font_y=clng(lngsize) 
end if 
end property 

'---------------取插入图片属性 
'插入图片的路径 
public property let picinpath(strtype) 
img_picin_path=strtype 
end property 
'图片插入的x坐标 
public property let picinx(lngsize) 
if isnumeric(lngsize) then 
img_picin_x=clng(lngsize) 
end if 
end property 
'图片插入的y坐标 
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 
'判断文件是否存在 
private function fileis(path) 
set fsos=server.createobject("scripting.filesystemobject") 
fileis=fsos.fileexists(path) 
set fsos=nothing 
end function 

'判断目录是否存在 
private function folderis(path) 
set fsos=server.createobject("scripting.filesystemobject") 
folderis=fsos.folderexists(path) 
set fsos=nothing 
end function 
'******************************************* 
'函数作用:取得当前文件的上一级路径 
'******************************************* 
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="指定文件不存在" 
case 1 
errors="指定目录不存在" 
case 2 
errors="已存在相同名称文件" 
case 3 
errors="参数溢出" 
end select 
end function 


'取图片宽度 
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 
'取图片高度 
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 
'生成缩略图/放大图 
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.width<img_reduce_size or aspjpeg_obj.height<img_reduce_size then 
set aspjpeg_obj_new=createobject("persits.jpeg") 
aspjpeg_obj_new.new img_reduce_size,img_reduce_size,&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 
'生成水印 
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.originalwidth<img_reduce_size or aspjpeg_obj.originalheight<img_reduce_size then 
img_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 
'生成框架 
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 
'生成水印字 
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 
%> 
这个类可以公开调用 
1. imginfo_height 取图片高度 
2. imginfo_width 取图片宽度 
调用方法: 
复制代码 代码如下:

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 height is "&pic_h  
response.write "this picture's width is "&pic_w  
response.end  

3. img_reduce 对指定图片缩小或放大并保存(可选择是否加水印,是否加框架) 
必须定义声明 mathpathfrom,mathpathto 
默认为缩放至150x150 图案 如按比例缩放后图案小于该尺寸,则补充空白图片 
默认文件自动覆盖 
实例: 
复制代码 代码如下:

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  
'图片操作过程中出现错误  
response.write "failed"  
end if  

4. img_watermark 给指定图片添加水印 
水印可以为图片 文字 或 2者结合 
软件
前端设计
程序设计
Java相关