ASPJpeg Sample Code

Root Folder > Web Hosting
Copy the following code and save it as pick_jpeg.asp.

<!-- 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>
<TITLE>AspJpeg Demo - Pick an Image</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<BASEFONT FACE="Arial" SIZE="2">

<TABLE WIDTH="550">
<TR><TD>

<H3><A HREF="AspJpeghttp://www.aspupload.com/aspjpeg.html">AspJpeg</A> Live Demo</H3>

<FONT SIZE="2"><B>Instructions:</B>
Select an image file from your hard drive for which you would
like to create thumbnails. Upload it to our
server using the form below. Once the image is uploaded,
you will be given the opportunity to
specify various resizing options.
<P>
No images handy? No problem!
We have put together a few large high-quality images you can experiment with.
<A HREF="jpegimages.zip">Download them here</A>.

</FONT>

<FORM ACTION="upload_jpeg.asp" METHOD="POST" ENCTYPE="multipart/form-data">
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="2">
 <TR><TD BGCOLOR="#E0FFF0" ALIGN="CENTER"><FONT FACE="Arial" SIZE="2" COLOR="#000000"><B>Select an Image</B></FONT></TD></TR>
 <TR><TD BGCOLOR="#EEEEEE"><INPUT TYPE="FILE" NAME="myFile" SIZE="40"></TD></TR>
 <TR><TD BGCOLOR="#EEEEEE"><INPUT TYPE="SUBMIT" VALUE="Upload Image"></TD></TR>
</TABLE>
</FORM>

<P>
<FONT SIZE="2"><A HREF="demo_jpeg.zip">Download source code for this demo</A></FONT>

</TD></TR>
</TABLE>

</BASEFONT>
</BODY>
</HTML>


Copy the following code and save it as upload_jpeg.asp

<!-- 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>
<TITLE>JPEG Upload Script</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<%
 Set Upload = Server.CreateObject("Persits.Upload")
 Upload.OverwriteFiles = False
 Upload.SetMaxSize 3000000, True

 On Error Resume Next 
 Count = Upload.SaveVirtual("/upload/jpeg")

 If Err <> 0 or Count = 0 Then
  
%>

<FONT SIZE="3" FACE="Arial" COLOR="#FF0000"><% If Err <> 0 Then Response.Write "An error occurred:" & Err.Description Else Response.Write "Nothing has been uploaded."%></B></FONT>
<P>
<FONT SIZE="2" FACE="Arial"><A HREF="pick_jpeg.asp">Try again</A>.</FONT>

<%  
 Else
  On Error Goto 0
  Set File = Upload.Files(1)
  If File.ImageType = "UNKNOWN" Then
   File.Delete
%>
<FONT SIZE="3" FACE="Arial" COLOR="#FF0000">This is not a valid image file.</B></FONT>
<P>
<FONT SIZE="3" FACE="Arial"><A HREF="pick_jpeg.asp">Try again</A>.</FONT>
<%  Else
%>

<FONT SIZE="2" FACE="Arial">
<B>The following <% = File.ImageType%> image has been uploaded:</B><P>
<TABLE CELLSPACING="0" CELLPADDING="2" BORDER="1">
 <TR><TD><FONT SIZE="2" FACE="Arial"><B>Path:</B></FONT></TD>
 <TD><FONT SIZE="2" FACE="Arial"><% = File.OriginalPath %></FONT></TD></TR>
 <TR><TD><FONT SIZE="2" FACE="Arial"><B>Size:</B></FONT></TD>
 <TD><FONT SIZE="2" FACE="Arial"><% = File.Size %> bytes</FONT></TD></TR>
 <TR><TD><FONT SIZE="2" FACE="Arial"><B>Dimensions:</B></FONT></TD>
 <TD><FONT SIZE="2" FACE="Arial"><% = File.ImageWidth %> x <% = File.ImageHeight %> pixels</FONT></TD></TR>
</TABLE>
<P>
<FORM ACTION="thumbnail.asp" METHOD="GET">
 <INPUT TYPE="HIDDEN" NAME="Path" VALUE="<% = File.Path%>">
 <INPUT TYPE="HIDDEN" NAME="Height" VALUE="<% = File.ImageHeight %>">
 <INPUT TYPE="HIDDEN" NAME="Width" VALUE="<% = File.ImageWidth %>">
 <INPUT TYPE="HIDDEN" NAME="scale" VALUE="50">
 <INPUT TYPE="HIDDEN" NAME="NewWidth" VALUE="100">
 <INPUT TYPE="HIDDEN" NAME="NewHeight" VALUE="100">
 <INPUT TYPE="HIDDEN" NAME="ResizeOption" VALUE="1">
 <INPUT TYPE="HIDDEN" NAME="Quality" VALUE="1">
 <INPUT TYPE="HIDDEN" NAME="Sharpen" VALUE="">
 <INPUT TYPE="HIDDEN" NAME="SharpenValue" VALUE="130">
 <INPUT TYPE="HIDDEN" NAME="Rotate" VALUE="0">
 <INPUT TYPE="SUBMIT" VALUE="Continue..."> 
</FORM>
<P>
<IMG SRC="/upload/jpeg/<% = File.ExtractFileName %>">
<P>
<FONT SIZE="2" FACE="Arial"><A HREF="pick_jpeg.asp">Upload another image</A></FONT>

</FONT>
<%

  End If
 End If
%>

</BODY>
</HTML>


Copy the following code and save it as thumbnail.asp

<!-- 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>
<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> <FONT SIZE="1" COLOR="#FF0000">(AspJpeg 1.2 Beta)</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>


At the end copy this code and save it as send_binary.asp

<%
 Response.Expires = 0
 
 ' 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")
 
 ' 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
%>


Copy these files to your website and try to manipulate Jpeg files with pick_jpeg.asp

Add Feedback