Link to home
Start Free TrialLog in
Avatar of elliottbenzle
elliottbenzle

asked on

how do I use persits aspJpeg to upload a file

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

Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

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")
Avatar of elliottbenzle
elliottbenzle

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/")%>">
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.