当前位置:编程学习 > html/css >>

如何用div+css压缩图片

追问:你这样 那图片会失真的 知道不???310x205??????? 真汗颜咯哈哈哈 是呀
答案:给你一个过程你看下
<%
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=# onclick=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=# onclick=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=# onclick=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 
%>



其他:把图片放置到一个DIV里,设置图片的高和宽都是 100%,然后你就控制DIV的宽和高来缩放图片的大小可以了。
代码如下:
<div style="width:40px; height:30px;"><img src="d_r2_c4.jpg"  style="width:100%; height:100%;"/></div>

谢谢采纳O(∩_∩)O~!!! 直接在CSS里写 width height 

上一个:CSS里,图片横排和文字横排(图片各自的内容在下面)
下一个:使用xamp集成本地服务站点建立的wordpress,php部分已写完,如何放到dreamweaver 写style.css 。

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,