![]() |
|
|
Published: Wednesday, May 03, 2000 By Mike Shaffer
In a recent small project, I needed a way to display a series of images in a square area (150x150 pixels). The images in question are uploaded by our customers, and we have no real control over what size or color depth (or even type) they are. While it's easy to force a resize of an image to, say, 150 pixels wide x 150 pixels high, you run the risk of stretching the image incorrectly in one dimension. And if you simply decide to force the width of the image to 150 and leave the height proportional (or vice-versa), then you may exceed the boundaries of 150 pixels. This is a problem. Fortunately, the solution is relatively easy. All we need is a tool that will report the dimensions (and color depth) of any image. I looked out on the web and found several that will do the trick. Of those, some were relatively inexpensive, and some were even free, but all of them were distributed as components. While there is certainly nothing wrong with that, I wanted something that could run entirely within an ASP page, without needing the ability to register a component on the server (since many people are unable to do so). Therefore, what follows is a set of routines (written in VBScript for your ASP pages) which will determine the height, width, and color depth of any GIF, JPG, BMP or PNG file. Additionally, these routines do not rely on the file extension to determine the graphic file-type. In other words, you can dynamically point this routine to any filename, regardless of name and extension, and determine if is a valid graphic file (actually, there is a very small chance [roughly one in 17 million] that a non-graphic file chosen at random will appear to be a graphics file, so it would be more appropriate to say that this routine determines PROBABLE graphic formats). Here are some possible uses for these routines:
The comments in the routine should be sufficient to help you get started. The only real thing you need to
understand is the format of the call to the main routine,
where:
The routine returns FALSE if the file was not recognized as a valid image type, and TRUE if it is 'probably' a valid image file. So there you have it, a complete new tool for your arsenal, with all VBScript source code, and best of all, IT'S FREE! (For a good ListServ that discusses graphics and ASP, be sure to join the ASP Graphics ListServ.)
Happy programming!
Attachments: imgsz.asp in text format
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||