web 2.0

How to use ASP & Upload and Resize image

How to use ASP & Upload and Resize image This is learn/tutorial asp developers how to using ASP script upload file and resize images

ShotDev Focus:
- ASP & Upload file and resize images

Example

asp_upload_resize1.asp


<% Option  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form action="asp_upload_resize2.asp" method="post" enctype="multipart/form-data" name="frmMain">
Upload
<input name="file1" type="file">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

asp_upload_resize2.asp


<% Option  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim sFileName,strPath
Dim mySmartUpload

strPath = "MyResize"

'*** Upload By aspSmartUpload ***'

'*** Create Object ***'
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

'*** Upload Files ***'
mySmartUpload.Upload

'** Getfile Name ***'
sFileName = mySmartUpload.Files("file1").FileName

If sFileName <> "" Then
'*** Upload **'
mySmartUpload.Files("file1").SaveAs(Server.MapPath(strPath&"/"&sFileName))

'********* Resize Images *******'
Response.write("<b>Oritial Size</b><br><img src=MyResize/"&sFileName&"><hr>")
Response.write("<b>New Size</b>")

Dim Chs, objConst,NewWidth,NewHeight
Dim OutFormat,OutFileName
OutFormat = "Jpg" '*** Gif,Png ***'
OutFileName = "Thumbnails_"&sFileName
NewWidth = "100" '*** Set new Width , Height automatic caculate ***'
NewHeight = 0 '*** Auto Resize ***'

'*** Get Images Width & Height ***'
Dim objFso,myImg,Width,Height
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
IF objFso.FileExists(Server.MapPath(strPath&"/"&sFileName))  Then
set myImg = Loadpicture(Server.MapPath(strPath&"/"&sFileName))
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(strPath&"/"&sFileName), objConst.chStretchPlot, , objConst.chAllFaces
Chs.border.color = -3

'Chs.border.color = &H0000FF
'Chs.border.Weight = 3

Chs.ExportPicture Server.MapPath(strPath&"/"&OutFileName),OutFormat,NewWidth,NewHeight

Set objConst = Nothing
Set Chs = Nothing
Response.write("<br><img src="&strPath&"/"&OutFileName&">")
'***** End  Resize Images ******'
End IF
%>
</body>
</html>

Create a asp file and save to path root-path/myasp/

Run
http://localhost/myasp/asp_upload_resize1.asp

Screenshot

ASP & Upload Resize image

ASP & Upload Resize image

ASP & Upload Resize image
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

One Response to “How to use ASP & Upload and Resize image”

  1. 3avenger…

Leave a Reply

You must be logged in to post a comment.