So a fair amount of my clients need to display images on their websites, they want to be able to upload an image of any size and make it fit with the layout of the website without any thinking. So we use AspJpeg. it makes resizing images on the fly easy and doesn’t slow down the server that much. This lesson we will be looking at the way to make any image resize and keep the aspect ratio but keep the width the same.

I normally make a file called resize_width.asp and include this code in.

<%

‘ IMPORTANT: This script must not contain any HTML tags

‘ Create an instance of AspJpeg object

Set jpeg = Server.CreateObject(“Persits.Jpeg”)

‘jpeg.Open( Request(“path”) )

jpeg.Open(“C:\DomainName\wwwroot\” & Request.QueryString(“path”))

‘you can use either of the above. my suggestion is the second one as it doesn’t reveal the whole path to the users.

‘ New width

L = Request(“size”)

jpeg.PreserveAspectRatio = True

jpeg.Width = L

‘ Send thumbnail data to client browser

jpeg.SendBinary

%>

This file would then be called like this:

<img src=”http://outsourcehouse.co.za/resize.asp?path=<%=(rsRandom_ads.Fields.Item(“ads_image”).Value)%>&size=180″ alt=”<%=(rsRandom_ads.Fields.Item(“ads_name”).Value)%>” />

Obviously the <%=(rsRandom_ads.Fields.Item(“ads_image”).Value)%> field would contain something like this:

/images/logo_for_company.jpg

And <%=(rsRandom_ads.Fields.Item(“ads_name”).Value)%> would contain an ALT tag of something like this:

Company Name

So the browser would read it as:

<img src=”http://outsourcehouse.co.za/resize.asp?path=/images/logo_for_company.jpg&size=180″ alt=”Company Name” />

Hope that helps you.

If you want to resize an image so that it is a square no matter what original size it was check out this link:

http://outsourcehouse.co.za/2010/05/31/aspjpeg-how-to-resize-a-image-into-a-square/

About Paul Ogier

Paul Ogier has written 202 posts.

Paul Ogier is an IT Guru, Website Developer, and generally a nice guy. He loves code and he loves design.

Incoming search terms for the article: