[These pages contain ready ASP scripts. You can use them in your own applications]

ASP SCRIPT: Creating thumbnail of image file


Note: all scripts examples included in these Web pages are absolutely free. You can copy, use, and modify these scripts anyway you want. The scripts are published without warranty of any kind.

What is this

To create a preview of image file you should shrink the image, keeping aspect ratio. The term "shrink" in this example means real image reducing, but not pseudo-redusing using HTML image size tags only. This example demonstrates the usage of ShotGraph local clipboard capabilities, and also GetFileDimensions, ReadImage functions.

This example is an ASP script creating the image. It does the following:

  1. gets information about image file
  2. calculates the preview image size
  3. loads image file into imagespace
  4. changes the size of image in the imagespace
  5. outputs the resulting image using Response.BinaryWrite

Note

Make sure your NT account for ASP has permissions to read the image file!

File reduce.asp
<%
Response.Contenttype="image/jpeg"
Set g=CreateObject("shotgraph.image")
'   This is the absolute path to image file.
'   You can get it anyway as you want, for example using
'   Request.Form or Request.QueryString for file name and then
'   adding that value to directory path.
'   Current string means the image file is located in the same directory
'   with ASP script
file_name = Server.MapPath("big01.jpg")
'   The maximal dimensions for new image
x_new=100
y_new=100

Main()

Sub Main()
t=g.GetFileDimensions(file_name,x,y)
if x<=0 or y<=0 then Exit Sub
if x/x_new > y/y_new then
	xset=x_new
	yset=y*x_new\x
else
	yset=y_new
	xset=x*y_new\y
end if
if xset<=0 then xset=1
if yset<=0 then yset=1
g.CreateImage xset,yset,4
g.InitClipboard x,y
g.SelectClipboard True
g.ReadImage file_name,pal,0,0
g.Stretch 0,0,xset,yset,0,0,x,y,"SRCCOPY","HALFTONE"
g.SelectClipboard False
Response.BinaryWrite g.JpegImage(70,0,"")
End Sub
%>


Back to examples