以下是 例子
程序代码
<form id="form1" name="form1" method="post" action="?action=test">
<textarea name="body" cols="50" rows="5" id="body">
<img height="180" src="https://www.easck.com/d/file/190113/10401W1S-0.jpg" width="240" border="0" />
<img class="left"src="https://www.easck.com/d/file/190113/10401W559-1.gif" width="114" />
<img height="60" src="https://www.easck.com/d/file/190113/10401W1O-2.jpg" width="120" border="0" />
<img height="60" alt="中国维和人数大国之首" src="https://www.easck.com/d/file/190113/10401R241-3.jpg" width="120" border="0" />
</textarea>
<input type="submit" name="Submit" value="提交" />
</form>
<%
if request.QueryString("action")="test" then
'图片开始的字符串
FilesStartStr="src="
'图片结束的字符串
FilesOverStr="gif|jpg|bmp"
'保存图片的文件夹
FilesPath="qq"
'取得保存图片的网站URL 自动判断是绝对 还是相对路径 该例子中图片是绝对地址 所以NEWURL等于没用 如果是../images/123.gif这样的 就需要指定NEWURL了
NewsUrl="http://news.163.com"
'取得文章内容
Content =Request.Form("body")
'开始保存图片
Content=ReplaceSaveRemoteFile(Content,FilesStartStr,FilesOverStr,False,True,True,FilesPath,NewsUrl)
'对新闻中的第一张图片创建缩略图
if GetImg(Content,FilesPath)<>"" then
Imgsrc=GetImg(Content,FilesPath)
Imgsrc=replace(Imgsrc,FilesPath,"")
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Path = Server.MapPath(""&FilesPath&"") & ""&Imgsrc&""
Jpeg.Open Path
'如果图片宽小于等于120 高小于等于90 则不创建缩略图
if Jpeg.OriginalWidth<=120 and Jpeg.Height<=90 then
Jpeg.Width = Jpeg.OriginalWidth
Jpeg.Height = Jpeg.OriginalHeight
Smallimg=FilesPath&""&GetImg(Content,FilesPath)
else
'图片宽度高度/2
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
Jpeg.Save Server.MapPath(""&FilesPath&"") & "small_"&Imgsrc&""
Smallimg=""&FilesPath&"/small_"&Imgsrc&""
end if
end if
'显示结果
response.Write("新闻中的第一张图片是:")
response.Write("<img src="&FilesPath&"/"&GetImg(Content,FilesPath)&">")
response.Write("<br>新闻中的第一张图片的缩略图是:")
response.Write("<img src="&Smallimg&">")
response.Write("<br>新的新闻内容(图片为本地):<br>")
Response.Write(Content)
Response.End()
end if
%>
您可能感兴趣的文章:
利用ASPUPLOAD,ASPJPEG实现图片上传自动生成缩略图及加上水印Asp无组件生成缩略图的代码ASP.Net 上传图片并生成高清晰缩略图asp.net 自定义控件实现无刷新上传图片,立即显示缩略图,保存图片缩略图Asp.Net平台下的图片在线裁剪功能的实现代码(源码打包)ASP组件AspJpeg(加水印)生成缩略图等使用方法asp.net 图片超过指定大小后等比例压缩图片的方法ASP.NET简单好用功能齐全图片上传工具类(水印、缩略图、裁剪等)ASP固定比例裁剪缩略图的方法