|
|
经典 ASP 确实可以用 WIA(Windows Image Acquisition) 来做缩略图,不用额外组件。
1.只支持常见图片格式
支持:
jpg
png
bmp
gif(静态)
不支持:
webp ❌
svg ❌
2.WIA 有时会对中文路径不稳定
建议:上传路径用英文或统一转 GUID 文件名
3.权限问题(常见)
IIS 账户必须有写权限:
/upload/
否则:SaveFile 会失败
4.质量问题
WIA压缩质量一般,不能调质量参数。如果你对画质要求高用第三方组件
- <%
- Function MakeThumb(srcPath, destPath, maxWidth, maxHeight)
- On Error Resume Next
- Dim img, ip
- Set img = CreateObject("WIA.ImageFile")
- img.LoadFile srcPath
- ' 原始尺寸
- Dim w, h, scale
- w = img.Width
- h = img.Height
- ' 计算缩放比例(等比)
- scale = 1
- If w > maxWidth Or h > maxHeight Then
- If w / maxWidth > h / maxHeight Then
- scale = maxWidth / w
- Else
- scale = maxHeight / h
- End If
- End If
- Dim newW, newH
- newW = Int(w * scale)
- newH = Int(h * scale)
- Set ip = CreateObject("WIA.ImageProcess")
- ' 添加缩放滤镜
- ip.Filters.Add ip.FilterInfos("Scale").FilterID
- ip.Filters(1).Properties("MaximumWidth") = newW
- ip.Filters(1).Properties("MaximumHeight") = newH
- ip.Filters(1).Properties("PreserveAspectRatio") = True
- ' 执行处理
- Set img = ip.Apply(img)
- ' 保存
- img.SaveFile destPath
- If Err.Number <> 0 Then
- MakeThumb = False
- Else
- MakeThumb = True
- End If
- Set img = Nothing
- Set ip = Nothing
- End Function
-
- Dim src, dest, ok
- src = Server.MapPath("/upload/4.jpg")
- dest = Server.MapPath("/upload/thumb/4_small.jpg")
- ok = MakeThumb(src, dest, 300, 300)
- If ok Then
- Response.Write "生成成功"
- Else
- Response.Write "生成失败"
- End If
- %>
复制代码
效果如下图:
|
|