Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How can I tell the dimensions of an image in ColdFusion?

ColdFusion does not have native image support (i.e., the ability to manipulate images) although it has been confirmed for the next version. However, there are multiple products that add this capability to ColdFusion. For this entry, we will look at ImageCFC, a free and open source solution created by Rick Root. This component provides multiple image manipulation options. To simply check the size of an image, you can use this code:

<cfset image = createObject("component", "image")>
<cfset info = image.getImageInfo("", expandPath("./storm.jpg"))>
<cfdump var="#info#">

The getImageInfo method returns a structure of data that contains information about the image, including its height and width. The same method can also be used to determine if a file is a valid image. If used against a non-image file, the returned structure will contain an error code with a value less than 0.


This question was written by Raymond Camden.
It was last updated on December 26, 2006 at 10:54:59 AM EST.

Categories

Miscellaneous

Comments

There are no comments for this entry.