Solved

Using ASP.VBScript how do I resize a picture that I have uploaded

Posted on 2008-10-24
6
1,207 Views
Last Modified: 2012-05-05
I am uploading pictures to a server. Sometimes people upload pictures that are too large. I want to be able to resize the pictures to width='250' and the height= a size relative to the original image size. Right now my page can upload the image and retrieve it's dimansions which it stores in two variables called myWidth and myHeight. How can I resize the image? Thanks for any help. I have attached my code below if anyone needs to see it.

Here is the page to see what it does now:
http://www.glowfishtw.com/benzleporcelain/productadd.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/dsnvessels.asp" -->
<!--#include file="Upload.asp" -->
<%
'Upload the image file and get reference to component
Dim Uploader, File
Set Uploader = GetASPUploader
 
'Use AddFile method to add file objects and change their properties as needed
Set File = Uploader.AddFile("file") 
 
'The the properties of the upload
File.ValidFileTypes = "pdf,jpg,gif,bmp,png"
File.MaxSize = 10240*1024
File.Overwrite = false 'Do not overwrite, create unique filename 
 
'Set the folder name to where the file will be uploaded to
Uploader.Destination = "Images" 
 
'Set longer timeout for large files if needed
Server.ScriptTimeout = 900
 
'Enable error handling to catch and handle errors during upload. For example, if user
'  cancels the upload or attempts to upload files of invalid (unallowed) type or size,
'  ASPUploader will raise an exception (error) with relevant description
On Error Resume Next
 
'Start receiving and saving file(s):
Uploader.Upload
 
'Check for errors:
If Err Then
  'Redirect with error message
  Response.Write err.description
  Response.End()
End If
 
 
'Add the details of the uploaded file to the database
Dim myFile, myDescrition, title, price, myWidth, myHeight, resolvedPath
resolvedPath = Server.MapPath(Uploader.Destination & "/" & File.name)
myFile="images/" & File.Name
myDescription=Uploader.Form("description")
title=Uploader.Form("title")
price=Uploader.Form("price")
Call sImageProperties(resolvedPath) 
 
myFile = Replace(myFile, "'", "''")
myDescription = Replace(myDescription, "'", "''")
title = Replace(title, "'", "''")
price = Replace(price, "'", "''")
 
response.write(myFile)
response.write(myDescription)
response.write(title)
response.write(price)
response.write("<br />")
response.write("resolvedpath=")
response.write(resolvedPath)
response.write("<br />")
response.write("width=")
response.write(myWidth)
response.write("<br />")
response.write("height=")
response.write(myHeight)
response.write("<br />")
response.write(Uploader.Destination)
 
 
 
 
 
set cadddetail = Server.CreateObject("ADODB.Command")
cadddetail.ActiveConnection = MM_dsnvessels_STRING
cadddetail.CommandText = "INSERT INTO products (ImageURL, name, description, price)  VALUES ( '" & myFile & "', '" & title & "', '" & myDescription & "', '" & price & "') "
cadddetail.CommandType = 1
cadddetail.CommandTimeout = 0
cadddetail.Prepared = true
cadddetail.Execute()
 
 
 
'Finally, void the object
 
 
Set Uploader=Nothing 
 
Sub sImageProperties(vImage)
  Dim image, fs
  Set fs=CreateObject("Scripting.FileSystemObject")
  If Not fs.fileExists(vImage) Then Exit Sub
  Set image = loadpicture(vImage)
  myWidth = Round(image.width / 26.4583)
  myHeight = Round(image.height / 26.4583)
  Set image = Nothing
  Set fs=Nothing
End Sub
%> 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style>
</head>
 
<body>
<p class="style1">New Product  uploaded</p>
<p><a href="productadd.asp">add a product </a></p>
<p><a href="productview.asp">delete/edit a product </a></p>
<p><a href="benzleupdate.asp">return to Benzle update </a></p>
<p><a href="index.asp">view Benzle Porcelain home page </a></p>
</body>
</html>

Open in new window

0
Comment
Question by:elliottbenzle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:R_Harrison
ID: 22796002
Slightly confused?  Normally you would just add the width tag to the <img> as below.

<img src="somepagethatgetstheimage.asp" width="250">

If you don't specify a height, the image height will be automatically adjusted to maintain the correct aspect ratio.

I am missing something?


0
 
LVL 9

Accepted Solution

by:
CCongdon earned 250 total points
ID: 22796177
@R Harrison: One problem is that if someone uploads a 10MB file, then all the users have to download that entire 10MB file for their browser to resize. If you get several of those on the same page..well then...that sucks.
I know a paid component isn't always the best solution, but I use aspJPEG. (www.persits.com). It does all kinds of image maniplulation include file-based (server-side) resize of the file down to a more manage-able size.
0
 
LVL 12

Expert Comment

by:R_Harrison
ID: 22796475
CCongdon:
Yeah, but you can always limit the size of the upload... anyway that wasn't the problem stated.  If he wants to actually change the image to a smaller version then he will need an external component...
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 9

Expert Comment

by:CCongdon
ID: 22796537
@R Harrison
Yeah, that's why I think the general public shouldn't be allowed cameras greater than a couple of megapixels unless they get a certificate showing that the understand how to resize photos before e-mailing/uploading them. :)
0
 
LVL 12

Expert Comment

by:R_Harrison
ID: 22796651
@CCongdon

With you on that one!  A 6 megapixal image squashed to 200 pixels, why oh why!
0
 
LVL 14

Assisted Solution

by:yessirnosir
yessirnosir earned 250 total points
ID: 22797312
What you are trying to accomplish is very common.  I'm a PHP guy so I can't help you with your code, but if you google "asp image resize upload" you'll get tons of hits.  eg. there is a good tutorial for a free way of doing this here:
http://www.codeproject.com/KB/web-image/pnguploader.aspx
It requires .NET rather than classic ASP, but it looks straightforward to implement.
The particular example converts the uploads to PNG format, but you can change that to your choice.
There are also links on the page to several other related examples, and down in the comments section under "good article, but i have a better solution" someone posted another complete solution that looks pretty good.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question