asp 上传图片 成比例缩小 并且可以设置图片的质量

<%
dim arr(3)
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft ''建立上传对象
      
formPath="../upImgFile/"     '图片存放的路径:product目录下的uploadimages文件夹       ''在目录后加(/)

''列出所有上传了的文件
    for each formName in upload.file
      set file=upload.file(formName)
   if file.filesize>0 then
      if file.filesize>10000000 then
  response.write "<font size=2>图片大小超小了限制[<a href=# οnclick=history.go(-1)>重新上传</a>]</font>"
  response.end
      end if
   fileExt=lcase(right(file.filename,4))
   if fileExt<>".jpg" then
         response.write "<font size=2>文件格式限制[<a href=# οnclick=history.go(-1)>请重新上传</a>]</font>"
         response.end
      end if
end if
      
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName

    if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
       file.SaveAs Server.mappath(formpath&filename)   ''保存文件

' 图片位置
dim PhotoPath
PhotoPath = Server.MapPath(formpath&filename)
'缩小大图
call OKbigpic(PhotoPath)

       'response.write file.FilePath&file.FileName&"("&file.FileSize&") => "&formPath&File.FileName&"上传成功<br>"
       response.write "上传成功 <a href=# οnclick=history.go(-1)>请返回</a>" 

    end if
set file=nothing
next
set upload=nothing
Response.Write "<script>parent.add.P_url.value='"&FileName&"'</script>"

sub OKbigpic(FileName)
Dim bigpic,bigpicPath,fss
Set bigpic = Server.CreateObject("Persits.Jpeg")
set fss=createobject("scripting.filesystemobject")
' 设置图片质量
bigpic.Interpolation=2   
bigpic.Quality=90   
' 图片位置
if fss.fileExists(FileName) then
bigpic.Open FileName


'下面是按比例缩放
n_MaxWidth=900
n_MaxHeight=1500

  '按比例取得缩略图宽度和高度
  Dim n_OriginalWidth, n_OriginalHeight '原图片宽度、高度
  Dim n_BuildWidth, n_BuildHeight '缩略图宽度、高度
  Dim div1, div2
  Dim n1, n2
  '修改Jpeg
  n_OriginalWidth = bigpic.Width
  n_OriginalHeight = bigpic.Height
  div1 = n_OriginalWidth / n_OriginalHeight
  div2 = n_OriginalHeight / n_OriginalWidth
  n1 = 0
  n2 = 0
  If n_OriginalWidth > n_MaxWidth Then
   n1 = n_OriginalWidth / n_MaxWidth
  Else
   n_BuildWidth = n_OriginalWidth
  End If
  If n_OriginalHeight > n_MaxHeight Then
   n2 = n_OriginalHeight / n_MaxHeight
  Else
   n_BuildHeight = n_OriginalHeight
  End If
  If n1 <> 0 Or n2 <> 0 Then
   If n1 > n2 Then
    n_BuildWidth = n_MaxWidth
    n_BuildHeight = n_MaxWidth * div2
   Else
    n_BuildWidth = n_MaxHeight * div1
    n_BuildHeight = n_MaxHeight
   End If
  End If

  '指定宽度和高度生成
  bigpic.Width = n_BuildWidth
  bigpic.Height = n_BuildHeight
  
' 保存文件
bigpic.Save (FileName)
' 注销对象
Set bigpic = Nothing


end if
end sub 
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值