% ' AutoImageSize - Aspect Ratio Guides Demo ' by Michael Kennedy ' http://www.unitedbinary.com ' mkennedy@unitedbinary.com set Resizer = Server.CreateObject ("ImageSize.AutoImageSize") ' Without registering, this will load a bit slow since there are so many ' images and each call to ChangeImageSize() gives a 2 second delay. ' These are the symbolic constants used. Call them whatever you want but the guides ' none,auto,width,height correspond to 0,1,2,3 respectively. ASPECT_RATIO_GUIDE_NONE = 0 ASPECT_RATIO_GUIDE_AUTO = 1 ASPECT_RATIO_GUIDE_WIDTH = 2 ASPECT_RATIO_GUIDE_HEIGHT = 3 ' Note: You'll need to replace the image files ' C:\Inetpub\wwwroot\images\wide.jpg ' C:\Inetpub\wwwroot\images\tall.jpg ' in the script with files that exist on your ' machine to run this page. %>
AutoImageSize 1.2+ implements the following aspect ratio guides:
Suppose you have a 1000x500 image and you attempt to resize it to 50x200. This guide realizes that the larger dimension in the actual image is the width, whereas the larger dimension in the resize request is the height. To perserve the aspect ratio and accomadate your request as close as possible, this guide will switch the order of the new image dimensions and transform your call into a request for a 200x50 image.
Next the guide considers the request for a 200x50 image with respect to the actual image dimesions of 1000x500. These are incompatible since 200/50 = 4 and 1000/500 = 2. Something has to give. The guide takes the maximum of the two new dimensions (max of 200 and 50) and uses that to resize the image and sets the smaller of the two to something accordingly. In this case, 200 >= 50 so the width of the new image will be 200 and to perserve the aspect ratio the height is set to 200*500/1000 = 100.
Here's the various guides in action. We use two images one called wide.jpg and a second called tall.jpg. As the name indicates (and you'll see) wide.jgp is a little wider than tall, and tall.jpg is taller than wide.
<% Resizer.SetAspectRatioGuide ASPECT_RATIO_GUIDE_AUTO%>
">
">
Guide = NONE
Function call: Resizer.ChangeImageSize("C:\wide.jpg",350,50) => 350x50
<% Resizer.SetAspectRatioGuide ASPECT_RATIO_GUIDE_NONE%>
">
Guide = WIDTH
Function call: Resizer.ChangeImageSize("C:\wide.jpg",100,1) => 100x66
Function call: Resizer.ChangeImageSize("C:\tall.jpg",100,1) => 100x235
<% Resizer.SetAspectRatioGuide ASPECT_RATIO_GUIDE_WIDTH%>
">
">
Guide HEIGHT
Function call: Resizer.ChangeImageSize("C:\wide.jpg",1,300) => 452x300
Function call: Resizer.ChangeImageSize("C:\tall.jpg",1,300) => 127x300
<% Resizer.SetAspectRatioGuide ASPECT_RATIO_GUIDE_HEIGHT%>
">
">
Have a look for youself: AutoImageSizeAspectGuideExpo.asp