How to use ASPJPEG to create thumbnails on-the-fly and get image dimensions and so on

Thumbnail Directory

I used this Components Tester and learned that an older (does jpg and jpegs only) version of ASJPEG is on my hosting provider's servers. OK, so how to use it? I checked the docs at Persits Software, but the information there wasn't dumbed-down enough for me to understand. Forget about asking the host's tech support staff, because those kids don't even know the component is there, let alone how to use it. ;) I persisted and finally figured out how to use it. OK, so how to make the thumbnails a specific size, and how to keep the same aspect ratio as the original image? I googled my way around the net and found a few bits of code to combine to do the job. (Posted below the test links that follow.) ORIGINAL IMAGES

Invoke a spell to make a thumbnail
(Wow, *PFM*!!!)
not the same thing as PMS
(Yes, I am a Buffy fan.)
makethumbs.asp?file=hard_knock_life.jpg
makethumbs.asp?file=bob_saget_bein_green.jpg
makethumbs.asp?file=bosch.jpg

Copy the following and paste into Notepad and then save as "makethumbs.asp." To invoke the spell, use a url such as this:
http://quarter-horse-times.com/aspexamples/thumbmaker.asp?file=<%= FILENAME %>

<%
dim iWidth, iHeight, iType
sub ImgDimension(img)
dim myImg, fs
Set fs= CreateObject("Scripting.FileSystemObject")
if not fs.fileExists(img) then exit sub
set myImg = loadpicture(img)
iWidth = round(myImg.width / 26.4583)
iHeight = round(myImg.height / 26.4583)
iType = myImg.Type
select case iType
case 0
iType = "None"
case 1
iType = "Bitmap"
case 2
iType = "Metafile"
case 3
iType = "Icon"
case 4
iType = "Win32-enhanced metafile"
end select
set myImg = nothing
end sub

ImgDimension(Server.MapPath("..\scripts") & "\aspsamples\" & request.querystring("file"))


Const MINPIXELS = 100

ImageHeight = iWidth
ImageWidth = iHeight
'*** calculate aspect ratio based on MINPIXELS
If iHeight > iWidth Then
NewHeight = Cint(ImageHeight*MINPIXELS/ImageWidth)
NewWidth = MINPIXELS
Else
NewWidth = Cint(ImageWidth*MINPIXELS/ImageHeight)
NewHeight = MINPIXELS
End If


Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Compute path to source image
Path = (Server.MapPath("..\scripts") & "\aspsamples\" & request.querystring("file"))



' Open source image
Jpeg.Open Path


Jpeg.Width = NewHeight
Jpeg.Height = NewWidth

' Apply sharpening if necessary
' Jpeg.Sharpen 1, 130

' create thumbnail and save it to disk
Jpeg.Save Server.MapPath("..\scripts") & "\aspsamples\thumbs\" & "TH_" & request.querystring("file")
%>
<b>SUCCESS!
</b><br>
Here is your thumbnail picture, <br><i><%="TH_" & request.querystring("file") %></i>:<br>
<% response.write"<img src="&"http://quarter-horse-times.com/scripts/aspsamples/thumbs/" & "TH_" & request.querystring("file") %>>
----------

BUT WAIT COLIN! YES RYAN? THERE'S MORE!


It is EVEN MORE SIMPLE...
I poked around some more looking at Persits very abbreviated examples, I figured out that keeping the aspect ratio of the original image AND specifying pixels for the width IS EVEN EASIER:
(Here follows makethumbs2.asp)


<%

Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Compute path to source image
Path = (Server.MapPath("..\scripts") & "\aspsamples\" & request.querystring("file"))

' Open source image
Jpeg.Open Path

' Set new width
jpeg.Width = 200
jpeg.Height = _
jpeg.OriginalHeight * jpeg.Width / jpeg.OriginalWidth

' Apply sharpening if necessary
' Jpeg.Sharpen 1, 130

' create thumbnail and save it to disk
Jpeg.Save Server.MapPath("..\scripts") & "\aspsamples\thumbs\" & "TH_" & request.querystring("file") %>
<b>SUCCESS!
</b><br>
Here is your thumbnail picture, <br><i><%="TH_" & request.querystring("file") %></i>:<br>
<% response.write"<img src="&"http://quarter-horse-times.com/scripts/aspsamples/thumbs/" & "TH_" & request.querystring("file") %>>

Try resizing our sample images again! This time, I have the thumbnails set to be 200 pixels so you can see the difference between makethumbs.asp and makethumbs2.asp.
makethumbs2.asp?file=hard_knock_life.jpg
makethumbs2.asp?file=bob_saget_bein_green.jpg
makethumbs2.asp?file=bosch.jpg

Colin, how much would you pay for information like this? I dunno Ryan, how much? WelL, colin, it gets even better! You can use aspjpeg to give you the dimensions of your images!

GET IMAGE DIMENSIONS:
dimensions.asp?file=hard_knock_life.jpg
dimensions.asp?file=bob_saget_bein_green.jpg
makethumbs.asp?file=bosch.jpg

I messed around some more with the sample code posted on the Persits site. The information said that ASPJPEG can be used to give you the dimensions of your images, but their examples were in combination with the use of AspUpload, which is not installed on the host I use. ("Pure ASP" upload scripts work fine here and it also has ASP Simple Upload.) As you have seen, I already am using code that reads back image file dimensions and other information. Even so, I was curious about how to use ASPJPEG for this. Some fiddling about produced the following example, saved as dimensions.asp:


<%

Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Compute path to source image
Path = (Server.MapPath("..\scripts") & "\aspsamples\" & request.querystring("file"))

' Open source image
Jpeg.Open Path

' Set new width
jpeg.Width = jpeg.OriginalWidth
jpeg.Height = jpeg.OriginalHeight

' Apply sharpening if necessary
' Jpeg.Sharpen 1, 130


%>
<b>DIMENSIONS OF <% = request.querystring("file")%>

</b><br>
<%=response.write(jpeg.OriginalWidth) %> pixels wide X <%=response.write(jpeg.OriginalHeight) %> high<br><br>
<% response.write"<img src="&"http://quarter-horse-times.com/scripts/aspsamples/" & request.querystring("file") %>>

I'm posting these things because I found the docs at the Persits site to be incomplete for someone like myself who is somewhat of an asp newbie, and I hope this information as I have written it will be helpful to someone else who is learning how to code in asp.

Rated:
by Aspin.com users
What do you think?

 

 

ASP Examples Menu of Active Server Pages scripts code Classic ASP

Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

If you find omissions or errors let me know. I have moved these code samples to their own domain; if you find pieces missing, please let me know.
My favorite scripts site is CODANGO.

*

If any the information I've posted here has been useful to you, please donate.

Quick 'n  easy  dirty PHP script code wizard-generator

Zenphoto RSS XML feed used as data source for javascript slide show with PHP

Classic ASP to archive emails into database and save attached files to folder

PHP Image GD for thumbnails and image resizing with pathing for Windows servers

ODBC database connections for Microsoft Access MDB files with Windows 7: solution posted on this forum.

HTML5 embedded video player "Projekktor" completely skinnable with hyperlinked watermark

Edit web.config to allow Windows iis7 server to handle mp4 files or other mime types as needed

URL rewrite or make friendly URLs for iis7 Windows Server 2008 by editing your web.config file

FACEBOOK API GEEWHIZ - INTEGRATE FACEBOOK WITH YOUR WEBSITE

Use PHP to zip folders for backing up a website

Use PHP to archive emails in database and save attached files to folder

Use PHP with json to check how many hits left on Twitter API

PHP get single record from Access database without catchable fatal error message

PHP to make a bot to send automatic Twitter status updates with Abraham Williams' PHP Oauth Twitter Library

A way to use the PHP Oauth Twitter Library with your Classic ASP scripts for sending status updates

Get user's IP address location for your form results

Tutorial for registering an application with Twitter

Update your Twitter status with Classic ASP and Oauth seamlessly and invisibly without having to login to Twitter. Send status updates programmatically from a web page. PHP example too.

CLASSIC ASP: Cache your Twitter tweets in a database to keep your Twitter xml requests within the rate limit of 350 per hour / PHP VERSION

PHP: Use json to fetch Twitter followers' profiles

Index files content and insert into database for faster searches

Classic ASP with Ajax: secure URL check

Classic ASP with Ajax: referer check

Classic ASP with Ajax: a solution to the ampersand problem in querystrings

Very Simple Star Rating System for Classic ASP

Star Rating System uses CSS and JS adapated for Classic ASP from Yvo Schaap PHP script

XMLhttp with ASP to fetch and save photos from Photobucket account through RSS XML. Can be adapted for Youtube videos to import data to database.

NET image resize can be used to make thumbnails for Classic ASP

Track site visitors, get their ip address geographical data, count page views with Classic ASP

Javascript slideshow with Classic ASP to load image details dynamically from database photos table

Classic ASP with Ajax for rotating banners without page refresh and XML file converted to recordset as banner database
--Variation of the above but fetching a REMOTE XML file as the database
--Variation checks for secure URL and builds absolute URL and makes offsite banner links open in new window

True inline edit Classic ASP datagrid table database edit updating with Ajax SIMPLE EASY without page refresh!

Use Ajax with Classic ASP to preview data then update form with javascript url write

Yvo Schaap's easy inline edit Ajax: an example of using it to inline edit multiple rows of records in Classic ASP

Use Classic ASP to send text messages SMS from your website (Also shows how to use xmlhttp to post form data)

Ajax with Classic ASP for seamless, no page reload database record insertion

Nested SQL Statements to make temporary column names

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

These are out of date but may still be of interest:

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.
ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script: can also be used for URL rewriting

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access (doesn't seem to work on Windows Server 2008)

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

From Classic ASP to PHP

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

BuildApp - great old Classic ASP script generator!

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker (For PHP I recommend EasyGen.)

If any of this information is helpful to you, please consider donating with the button below. Thanks! ~~Lil