Home
What's New

User Manual
1. Introduction
2. Simple Uploads
3. Memory Uploads
4. Database
5. Progress Bar
6. Security
7. Images
8. Unicode
9. Miscellaneous
10. Hosting Issues

Object Reference
Live Demos
Support

XUpload
JUpload
AspJpeg

Download
Purchase

Clients
Other Products
Contact Us

Newsletter Signup


Chapter 8: Unicode Support Chapter 6: User Impersonation and Permissions Chapter 7. Image Handling

Image Size and Type Extraction

AspUpload is capable of determining the type and pixel size of uploaded images. The formats currently supported are GIF, JPEG, BMP and PNG. The type and size information is returned via the properties File.ImageType, File.ImageWidth, and File.ImageHeight.

The property File.ImageType returns the strings "GIF", "JPG", "BMP", "PNG" (for GIF JPEG BMP and PNG images, respectively), or "UNKNOWN" if the file is not an image or of an unknown image type.

The properties File.ImageWidth and File.ImageHeight return the image width and height in pixels, or 0 if the file is not an image.

The code samples size.asp and size_upload.asp demonstrate the usage of these properties.

<!--#include file="AspUpload.inc"-->

<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload")

' Capture and save uploaded image
Upload.Save "c:\upload"

For Each File in Upload.Files
   If File.ImageType = "UNKNOWN" Then
      Response.Write "This is now an image."
      Response.End
   End If

   Response.Write File.Path & "<BR>"
   Response.Write "Type: " & File.ImageType & "<BR>"
   Response.Write "Size: " & File.ImageWidth & " x " & File.ImageHeight & " pixels"
Next
%>
</BODY>
</HTML>

Click the link below to run this code sample:

http://localhost/aspupload/07_image/size.asp  Why is this link not working?

Image Resizing
AspUpload can be used in conjunction with another Persits Software component, AspJpeg, to create resized versions and thumbnails of JPEG images. An evaluation copy of AspJpeg can be downloaded here.

The code samples resize.asp and resize_upload.asp demonstrate how AspJpeg can be used to resize a newly uploaded JPEG image. The uploaded and resized images are saved in the same directory as the ASP scripts, rather than the usual c:\upload folder, to be able to display both images in the browser easily.

<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload")

' Use AspJpeg to resize image
Set Jpeg = Server.CreateObject("Persits.Jpeg")

' Capture and save uploaded image to the same directory as script
Upload.Save Server.MapPath(".")

For Each File in Upload.Files
   If File.ImageType <> "JPG" Then
      Response.Write "This is now a JPGE image."
      File.Delete
      Response.End
   End If

   Jpeg.Open File.Path

   Scale = Upload.Form("Scale")
   Jpeg.Width = Jpeg.OriginalWidth * Scale / 100
   Jpeg.Height = Jpeg.OriginalHeight * Scale / 100
   Response.Write Jpeg.OriginalHeight & "-" & Jpeg.Height
   Jpeg.Save Server.MapPath(".") & "\small_" & File.FileName
%>
   <IMG SRC="<% = File.FileName %>"><BR>
   <IMG SRC="<% = "small_" & File.FileName %>"><P>
<%
Next
%>
</BODY>
</HTML>

Click the link below to run this code sample:

http://localhost/aspupload/07_image/resize.asp  Why is this link not working?

AspJpeg comes with many more code samples. A live demo is also available.

Chapter 8: Unicode Support Chapter 6: User Impersonation and Permissions

 


Copyright © 1998 - 2001 Persits Software, Inc.
All Rights Reserved
AspUpload® is a registered trademark of Persits Software, Inc.
Questions? Comments? Write us!