ASP Resize Image ในการเขียน ASP ทำการ Resize รูปภาพผมใช้ Component ของ OWC10.ChartSpace ซึ่งมีอยู่ใน Windows แล้วสามารถเรียกงานได้ในทันที
Syntax
Server.CreateObject("OWC10.ChartSpace")
Samle 1 ตัวอย่างแรกจะเป็นการ Resize โดยส่งออกแบบ Binary
AspResizeImages.asp
<%
Option Explicit
Dim Chs, objConst,NewWidth,NewHeight
Dim FileName,OutFormat
FileName = "mygirl.jpg"
OutFormat = "Jpg" '*** Gif,Png ***'
NewWidth = "100" '*** Set new Width , Height automatic caculate ***'
NewHeight = 0 '*** Auto Resize ***'
'*** Get Images Width & Height ***'
Dim objFso,myImg,Width,Height
Set objFso = CreateObject("Scripting.FileSystemObject")
IF objFso.FileExists(Server.MapPath(FileName)) Then
set myImg = Loadpicture(Server.MapPath(FileName))
Width = Round(myImg.width / 26.4583)
Height = Round(myImg.height / 26.4583)
NewHeight = Round((NewWidth*Height)/Width)
'NewHeight = 100
'NewWidth = Round((NewHeight*Width)/Height) '*** or Automatic Height ***'
End If
'*************** End *************'
Set Chs = Server.CreateObject("OWC10.ChartSpace")
Set objConst = Chs.Constants
Chs.Interior.SetTextured Server.MapPath(FileName), objConst.chStretchPlot, , objConst.chAllFaces
Chs.border.color = -3
Response.BinaryWrite Chs.GetPicture(OutFormat, NewWidth, NewHeight)
Set objConst = Nothing
Set Chs = Nothing
%>
ASPViewResizeImages.asp
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP Resize Images</title>
</head>
<body>
<b>Oritial Size</b><br>
<img src="mygirl.jpg">
<hr>
<b>New Size</b>
<br>
<img src="AspResizeImages.asp">
</body>
</html>
Screenshot
Sample 2 ตัวอย่างที่สองจะเป็นการ Save เป็นไฟล์ใหม่ลงในตำแหน่งที่ต้องการ
AspResizeImages2.asp
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP Resize Images</title>
</head>
<body>
<b>Oritial Size</b><br>
<img src="mygirl.jpg">
<hr>
<b>New Size</b>
<br>
<%
Dim Chs, objConst,NewWidth,NewHeight
Dim FileName,OutFormat,OutFileName
FileName = "mygirl.jpg"
OutFormat = "Jpg" '*** Gif,Png ***'
OutFileName = "MyResize/mygirl.jpg"
NewWidth = "100" '*** Set new Width , Height automatic caculate ***'
NewHeight = 0 '*** Auto Resize ***'
'*** Get Images Width & Height ***'
Dim objFso,myImg,Width,Height
Set objFso = CreateObject("Scripting.FileSystemObject")
IF objFso.FileExists(Server.MapPath(FileName)) Then
set myImg = Loadpicture(Server.MapPath(FileName))
Width = Round(myImg.width / 26.4583)
Height = Round(myImg.height / 26.4583)
NewHeight = Round((NewWidth*Height)/Width)
'NewHeight = 100
'NewWidth = Round((NewHeight*Width)/Height) '*** or Automatic Height ***'
End If
'*************** End *************'
Set Chs = Server.CreateObject("OWC10.ChartSpace")
Set objConst = Chs.Constants
Chs.Interior.SetTextured Server.MapPath(FileName), objConst.chStretchPlot, , objConst.chAllFaces
Chs.border.color = -3
'Chs.border.color = &H0000FF
'Chs.border.Weight = 3
Chs.ExportPicture Server.MapPath(OutFileName),OutFormat,NewWidth,NewHeight
Set objConst = Nothing
Set Chs = Nothing
%>
<img src="<%=OutFileName%>">
</body>
</html>
Screenshot
|