首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

ASPJPEG按比值缩放并按指定大小裁剪修改

2013-08-10 
ASPJPEG按比例缩放并按指定大小裁剪修改 按比例缩放并按指定大小裁剪(原代码是,竖的要剪掉上下部分,模的,

ASPJPEG按比例缩放并按指定大小裁剪修改
 按比例缩放并按指定大小裁剪(原代码是,竖的要剪掉上下部分,模的,要剪掉左右部分,模的可以接受这样,但竖的不行)
求修改-比如竖板的人物图片裁剪成方形成把头和脚都载了,能否修改成载掉图片下面部分保留上部分
function cutjpeg(byval cutfile,byval cwidth,byval cheight)
if not aspjpegobj or lcase(left(cutfile,7)) = "http://" then cutjpeg = cutfile :exit function
dim savefolder,savefile
savefolder = installdir & "uploadfile/small/" & replace(replace(replace(replace(lcase(cutfile),".jpg",""),"/",""),"uploadfile",""),".jpeg","") & "/"
savefile = savefolder & cwidth & "x" & cheight & ".jpg"
if fso.fileexists(server.mappath(savefile)) then
cutjpeg = savefile
Jpeg.Quality=100 
else
dim jpeg
dim jwidth,jheight,nwidth,nheight
dim x1,y1,x2,y2
on error resume next
set jpeg = server.createobject(strobjectjpeg)
jpeg.regkey = "48958-77556-02411"
jpeg.open server.mappath(cutfile)
jwidth = jpeg.originalwidth
jheight = jpeg.originalheight
if (jwidth/jheight)>=(cwidth/cheight) then
nwidth=cint((jwidth/jheight)*cheight):nheight=cheight
jpeg.width=nwidth:jpeg.height=nheight
x1=int((nwidth-cwidth)/2):y1=0:x2=x1+cwidth:y2=cheight

else
nwidth=cwidth:nheight=cint((jheight/jwidth)*cwidth)
jpeg.width=nwidth:jpeg.height=nheight
x1=0:y1=int((nheight-cheight)/2):x2=cwidth:y2=y1+cheight
end if
jpeg.crop x1,y1,x2,y2
jpeg.sharpen 1,130
call createfolder(savefile) ' 需要带个文件才可生成
jpeg.save server.mappath(savefile)
set jpeg = nothing
if err then
cutjpeg = cutfile : err.clear
else
cutjpeg = savefile
end if
end if
end function
[解决办法]

引用:
 按比例缩放并按指定大小裁剪(原代码是,竖的要剪掉上下部分,模的,要剪掉左右部分,模的可以接受这样,但竖的不行)
求修改-比如竖板的人物图片裁剪成方形成把头和脚都载了,能否修改成载掉图片下面部分保留上部分
function cutjpeg(byval cutfile,byval cwidth,byval cheight)
if not aspjpegobj or lcase(left(cutfile,7)) = "http://" then cutjpeg = cutfile :exit function


dim savefolder,savefile
savefolder = installdir & "uploadfile/small/" & replace(replace(replace(replace(lcase(cutfile),".jpg",""),"/",""),"uploadfile",""),".jpeg","") & "/"
savefile = savefolder & cwidth & "x" & cheight & ".jpg"
if fso.fileexists(server.mappath(savefile)) then
cutjpeg = savefile
Jpeg.Quality=100 
else
dim jpeg
dim jwidth,jheight,nwidth,nheight
dim x1,y1,x2,y2
on error resume next
set jpeg = server.createobject(strobjectjpeg)
jpeg.regkey = "48958-77556-02411"
jpeg.open server.mappath(cutfile)
jwidth = jpeg.originalwidth
jheight = jpeg.originalheight
if (jwidth/jheight)>=(cwidth/cheight) then
nwidth=cint((jwidth/jheight)*cheight):nheight=cheight
jpeg.width=nwidth:jpeg.height=nheight
x1=int((nwidth-cwidth)/2):y1=0:x2=x1+cwidth:y2=cheight

else
nwidth=cwidth:nheight=cint((jheight/jwidth)*cwidth)
jpeg.width=nwidth:jpeg.height=nheight
x1=0:y1=int((nheight-cheight)/2):x2=cwidth:y2=y1+cheight
end if
jpeg.crop x1,y1,x2,y2
jpeg.sharpen 1,130
call createfolder(savefile) ' 需要带个文件才可生成
jpeg.save server.mappath(savefile)
set jpeg = nothing
if err then
cutjpeg = cutfile : err.clear
else
cutjpeg = savefile
end if
end if
end function



求修改-比如竖板的人物图片裁剪成方形成把头和脚都载了,能否修改成载掉图片下面部分保留上部分

这个很简单的,你只要把下面这个
jpeg.crop x1,y1,x2,y2
里面的前面x1,y1  这个2个参数改成0,0他就会是保留上面部分了,当然主要是y1这个参数是控制上下的,x1主要是控制左右的
[解决办法]
引用:
求修改-比如竖板的人物图片裁剪成方形成把头和脚都载了,能否修改成载掉图片下面部分保留上部分

这个很简单的,你只要把下面这个
jpeg.crop x1,y1,x2,y2
里面的前面x1,y1  这个2个参数改成0,0他就会是保留上面部分了,当然主要是y1这个参数是控制上下的,x1主要是控制左右的


修改了半天,没有成功,请大师能否再明白一点

已经解释的很明白了吧

jpeg.crop x1,y1,x2,y2
里面的前面x1,y1  这个2个参数改成0,0他就会是保留上面部分了,当然主要是y1这个参数是控制上下的,x1主要是控制左右的
你只要针对x1,y1进行调整,也就是这个2个参数值控制从哪里开始切割裁剪,自己多试试不就知道了
如果改成0,0就是表示从左上角开始切割裁剪

热点排行