web 2.0

How to use ASP & Resize image and insert to database

How to use ASP & Resize image and insert to database This is learn/tutorial asp developers how to using ASP script Resize image and insert to database.

ShotDev Focus:
- ASP & Resize image and insert to database.

Example

asp_upload_resize2.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 mySmartUpload
Dim Conn,strSQL,objExec

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

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

Dim sFileName,strPath
strPath = "MyResize"
sFileName = mySmartUpload.Files("file1").FileName

'*** Upload file1 ***'
If mySmartUpload.Files("file1").FileName <> "" Then
mySmartUpload.Files("file1").SaveAs(Server.MapPath(strPath & "/" & sFileName))
Response.write sFileName & " Resize Successful.<br>"

'*** Resize Images ***'

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

'*** Insert Record ***'
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
strSQL = ""
strSQL = strSQL &"INSERT INTO files "
strSQL = strSQL &"(Thumbnails,FilesName) VALUES ('"&OutFileName&"','"&sFileName&"')"
Set objExec = Conn.Execute(strSQL)

End If

Response.write("<a href=asp_upload_resize3.asp>View files</a>")

Set mySmartUpload = Nothing
%>
</body>
</html>

asp_upload_resize3.asp


<% Option  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM files "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
%>
<table width="200" border="1">
<tr>
<th width="50"> <div align="center">Files ID </div></th>
<th width="150"> <div align="center">Resize </div></th>
</tr>
<%
While Not objRec.EOF
%>
<tr>
<td><div align="center"><%=objRec.Fields("FilesID").Value%></div></td>
<td><center>
<a href="MyResize/<%=objRec.Fields("FilesName").Value%>">

<img src="MyResize/<%=objRec.Fields("Thumbnails").Value%>" border="0"></a></center>
</td>
</tr>
<%
objRec.MoveNext
Wend
%>
</table>
<%
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
<br>
<a href="asp_upload_resize1.asp">New Upload</a>
</body>
</html>

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

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

Screenshot

ASP & Resize image and insert to database.

ASP & Resize image and insert to database.

ASP & Resize image and insert to database.
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.