Solved

how do I use persits aspJpeg to upload a file

Posted on 2008-10-25
5
1,055 Views
Last Modified: 2008-10-26
I'm trying to use ASPupload and ASPjpeg (persits software) to resize an image and then upload the resized image. I've gotten a test site to upload the original image and then resize the image and store the resized image in a variable which is displayed on the screen. I want the new image to be saved/uploaded when the user hits the "create thumbnail" button. Here is the site now:

http://www.glowfishtw.com/uploadtest/pick_jpeg.asp

I would like the page to upload the new resized image to this destination: (Server.Mappath("image/"))

Here is the code given me by persits, but I can't figure out which part of it to put where in my code to make the image upload.

Attached is my code. Can someone please show me how to make this work.

<%
' Create instance of AspJpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")

' Open source image
Jpeg.Open "c:\path\myimage.jpg"

' New width
L = 100

' Resize, preserve aspect ratio
Jpeg.Width = L
Jpeg.Height = Jpeg.OriginalHeight * L / Jpeg.OriginalWidth

' create thumbnail and save it to disk
Jpeg.Save "c:\path\thumbnail.jpg"

%>
-------------CODE FOR UPLOAD PAGE -------------------------------------
 
<!-- Copyright (c) 2000 Persits Software, Inc.-->
<!-- For more information on AspJpeg, and to download your free eval version-->
<!-- visit http://www.aspupload.com -->
 
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>Create a Thumbnail</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
 
<FONT FACE="Arial" Size=2"><B>The dimensions of the original image are <% = Request("Width") %> x <% = Request("Height") %></B></FONT>
<P>
<FONT SIZE="2" FACE="Arial"><A HREF="pick_jpeg.asp">Upload another image</A></FONT>
<P>
<FORM ACTION="thumbnail.asp" METHOD="POST" NAME="MainForm">
	<INPUT TYPE="HIDDEN" NAME="Path" VALUE="<% = Request("Path") %>">
	<INPUT TYPE="HIDDEN" NAME="Width" VALUE="<% = Request("Width") %>">
	<INPUT TYPE="HIDDEN" NAME="Height" VALUE="<% = Request("Height") %>">
 
	<TABLE BGCOLOR="#E0FFF0" BORDER="1" CELLSPACING="0" CELLPADDING="2">
	<TR><TD><INPUT TYPE="RADIO" NAME="ResizeOption" VALUE="1" <% If Request("ResizeOption") = "1" Then Response.Write "CHECKED" %>><FONT SIZE="2" FACE="Arial">Scale to</FONT></TD>
		<TD><SELECT NAME="scale" onFocus="document.MainForm.ResizeOption[0].checked = true">
			<OPTION VALUE="200" <% If Request("scale") = "200" Then Response.Write "SELECTED" %>>200%
			<OPTION VALUE="80" <% If Request("scale") = "80" Then Response.Write "SELECTED" %>>80%
			<OPTION VALUE="50" <% If Request("scale") = "50" Then Response.Write "SELECTED" %>>50%
			<OPTION VALUE="25" <% If Request("scale") = "25" Then Response.Write "SELECTED" %>>25%
			<OPTION VALUE="10" <% If Request("scale") = "10" Then Response.Write "SELECTED" %>>10%
			</SELECT>
		</TD></TR>
	<TR><TD><INPUT TYPE="RADIO" NAME="ResizeOption" VALUE="2" <% If Request("ResizeOption") = "2" Then Response.Write "CHECKED" %>><FONT SIZE="2" FACE="Arial">Set width to</FONT></TD>
	<TD><INPUT TYPE="TEXT" NAME="NewWidth" SIZE="5" VALUE="<% = Request("NewWidth")%>" onFocus="document.MainForm.ResizeOption[1].checked = true"> <FONT SIZE="2" FACE="Arial">pixels, preserve Width/Height ratio</FONT></TD>
	</TR>
 
	<TR><TD><INPUT TYPE="RADIO" NAME="ResizeOption" VALUE="3" <% If Request("ResizeOption") = "3" Then Response.Write "CHECKED" %>><FONT SIZE="2" FACE="Arial">Set height to</FONT></TD>
	<TD><INPUT TYPE="TEXT" NAME="NewHeight" SIZE="5" VALUE="<% = Request("NewHeight")%>" onFocus="document.MainForm.ResizeOption[2].checked = true"> <FONT SIZE="2" FACE="Arial">pixels, preserve Width/Height ratio</FONT></TD>
	</TR>
 
	<TR><TD COLSPAN="1"><INPUT TYPE="CHECKBOX" NAME="Quality" <% If Request("Quality") <> "" Then Response.Write "CHECKED" %>><FONT SIZE="2" FACE="Arial">High Quality</FONT></TD>
	<TD COLSPAN="1">
		<INPUT TYPE="CHECKBOX" NAME="Sharpen" <% If Request("Sharpen") <> "" Then Response.Write "CHECKED" %>>
		<FONT SIZE="2" FACE="Arial">Sharpen at</FONT>
			<INPUT TYPE="TEXT" SIZE="4" NAME="SharpenValue" VALUE="<% = Request("SharpenValue")%>" onFocus="document.MainForm.Sharpen.checked = true">
			<FONT SIZE="2" FACE="Arial">% (must be > 100)</FONT>
		</TD>
	</TR>
 
	<!-- this will be implemented with version 1.2+-->
	<TR><TD COLSPAN="2" ALIGN="CENTER"><FONT SIZE="2" FACE="Arial">
		<INPUT TYPE="RADIO" NAME="Rotate" VALUE="1" <% If Request("Rotate") = "1" Then Response.Write "CHECKED" %>> 
		Rotate left
		<INPUT TYPE="RADIO" NAME="Rotate" VALUE="0" <% If Request("Rotate") = "0" Then Response.Write "CHECKED" %>>
		No rotation
		<INPUT TYPE="RADIO" NAME="Rotate" VALUE="2" <% If Request("Rotate") = "2" Then Response.Write "CHECKED" %>>
		Rotate right</FONT></TD>
	</TR>
 
	<TR><TD COLSPAN="2"><INPUT TYPE="SUBMIT" NAME="create" VALUE="Create Thumbnail"></TD></TR>
	
	</TABLE>
</FORM>
 
<P>
 
<%
If Request("Create") <> "" Then
 
	Path = Request("Path")
 
	If Request("Quality") <> "" Then
		Interpolation =	1 ' use Bilinear interpolation
	Else
		Interpolation =	0 ' use Nearest-neighbor algorithm
	End If
	
	If Request("Sharpen") <> "" Then
		Sharpen = "1"
		
		SharpenValue = Request("SharpenValue")
		If SharpenValue <= 100 Then
			Response.Write "<FONT FACE=""Arial""><B>Sharpening value must be greater than 100</B></FONT>"
			Response.End
		End If
	Else 
		Sharpen = "0"
	End If
 
	' resize according to user selection
 
	' Percentage scaling
	If Request("ResizeOption") = 1 Then
		Scale = Request("scale") / 100
		Height = Request("Height") * Scale
		Width = Request("Width") * Scale
	End If
 
	' user-specified width
	If Request("ResizeOption") = 2 Then
		If IsNumeric(Request("NewWidth")) Then Width = Request("NewWidth") Else Width = 0
		If Width > 0 and Width < 2000 Then
			Height = Request("Height") * Width / Request("Width")
		Else
			Response.Write "<FONT FACE=""Arial""><B>Invalid Width value</B></FONT>"
			Response.End
		End If
	End If
 
	' user-specified height
	If Request("ResizeOption") = 3 Then
		If IsNumeric(Request("NewHeight")) Then Height = Request("NewHeight") Else Height = 0
		If Height > 0 and Height < 2000 Then
			Width = Request("Width") * Height / Request("Height")
		Else
			Response.Write "<FONT FACE=""Arial""><B>Invalid Height value</B></FONT>"
			Response.End
		End If
	End If
 
	Rotate = Request("Rotate")
 
	' Display image
%>
<IMG SRC="send_binary.asp?Path=<% = Server.URLEncode(Path) %>&Width=<% = Width%>&Height=<% = Height %>&Interpolation=<% = Interpolation %>&sharpen=<% = Sharpen %>&sharpenvalue=<% = SharpenValue%>&Rotate=<% = Rotate %>">
<%
End If
%>
 
 
</BODY>
</HTML>
 
 
 
-------------- CODE FOR SEND_BINARY PAGE -----------------------------
 
<%
	Response.Expires = 0
	
	Session.CodePage = 65001
	
	' create instance of AspJpeg
	Set jpg = Server.CreateObject("Persits.Jpeg")
	
	' Open source file
	jpg.Open( Request("path") )
 
	' Set resizing algorithm
	jpg.Interpolation = Request("Interpolation")
 
	' Set new height and width
	jpg.Width = Request("Width")
	jpg.Height = Request("Height")
	
	' Convert to RGB if this is a CMYK image
	jpg.ToRGB
	
	' Sharpen resultant image
	If Request("Sharpen") <> "0" Then 
		jpg.Sharpen 1, Request("SharpenValue")
	End If
 
	' Rotate if necessary. Only available in version 1.2
	If Request("Rotate") = 1 Then jpg.RotateL
	If Request("Rotate") = 2 Then jpg.RotateR
 
	' Perform resizing and 
	' send resultant image to client browser
	jpg.SendBinary
	
%>

Open in new window

0
Comment
Question by:elliottbenzle
  • 3
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Rouchie
ID: 22806596
How far have you actually got with this, as its a two-part problem.   The first stage is to upload the image and save it to the server/computer in your images directory.  Have you done this part?

The second part is resizing and displaying.

If you need to save to "images" then you should replace this line of code:
 
   ' create thumbnail and save it to disk
   Jpeg.Save "c:\path\thumbnail.jpg"

with this:

   ' create thumbnail and save it to disk
   Jpeg.Save Server.MapPath("images")
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 22807236
I've gotten everything to work except the uploading of the final resized file. There are two pages working here:
 The thumbnail page, in which the user defines the resize variables.
 The send_binary page, in which the image is processed and displayed on the thumbnail page.

I know that the line          Jpeg.Save Server.MapPath("images")      needs to be place somewhere on one of these pages but I don't know where. The send_binary page isn't actually run, it is just used to display and process the image as in this line (from thumbnail page):

%>
<IMG SRC="send_binary.asp?Path=<% = Server.URLEncode(Path) %>&Width=<% = Width%>&Height=<% = Height %>&Interpolation=<% = Interpolation %>&sharpen=<% = Sharpen %>&sharpenvalue=<% = SharpenValue%>&Rotate=<% = Rotate %>">
<%

So I don't think the upload script should go on the send_binary page.

I need to somehow resize and then upload the image when the user hits the "Create Thumbnail" button. Any help in the right direction would be great.

Elliott
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
ID: 22807766
Instead of calling jpg.sendBinary you should call jpg.save (According to the instructions).  SendBinary is just sending the raw image data to the browser as an image, when you actually need to save it after processing.

So open sendbinary.asp and change this line:

        jpg.SendBinary

to this:

        jpg.Save(SavePath)

Then in the main page, find this line:

%>
<IMG SRC="send_binary.asp?Path=<% = Server.URLEncode(Path) %>&Width=<% = Width%>&Height=<% = Height %>&Interpolation=<% = Interpolation %>&sharpen=<% = Sharpen %>&sharpenvalue=<% = SharpenValue%>&Rotate=<% = Rotate %>">
<%

and change the code to this:

%>
<IMG SRC="send_binary.asp?Path=<% = Server.URLEncode(Path) %>&Width=<% = Width%>&Height=<% = Height %>&Interpolation=<% = Interpolation %>&sharpen=<% = Sharpen %>&sharpenvalue=<% = SharpenValue%>&Rotate=<% = Rotate %>&SavePath=<%=Server.MapPath("images")%>">
<%

You notice I added a bit on the end which contains the path where the image will get saved.  So then we get sendbinary.asp to read that value and save.
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 22809751
I tried it but no luck. Is there a better way to be going about this? Here is what I have now.


Send Binary:

<%
      Response.Expires = 0
      
      Session.CodePage = 65001
      
      ' create instance of AspJpeg
      Set jpg = Server.CreateObject("Persits.Jpeg")
      
      ' Open source file
      jpg.Open( Request("path") )

      ' Set resizing algorithm
      jpg.Interpolation = Request("Interpolation")

      ' Set new height and width
      jpg.Width = Request("Width")
      jpg.Height = Request("Height")
      
      ' Convert to RGB if this is a CMYK image
      jpg.ToRGB
      
      ' Sharpen resultant image
      If Request("Sharpen") <> "0" Then
            jpg.Sharpen 1, Request("SharpenValue")
      End If      

      ' Rotate if necessary. Only available in version 1.2
      If Request("Rotate") = 1 Then jpg.RotateL
      If Request("Rotate") = 2 Then jpg.RotateR

      ' Perform resizing and
      ' send resultant image to client browser
      jpg.SendBinary
      
      jpg.Save(SavePath)

      
%>

Thumbnail



<IMG SRC="send_binary.asp?Path=<% = Server.URLEncode(Path) %>&Width=<% = Width%>&Height=<% = Height %>&Interpolation=<% = Interpolation %>&sharpen=<% = Sharpen %>&sharpenvalue=<% = SharpenValue%>&Rotate=<% = Rotate %>&SavePath=<%=Server.MapPath("images/")%>">
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 22810221
I got around it by creating a new page for the ASPjpeg upload portion of the code and by passing the Send_Binary page altogether. Thanks for the help.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

821 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