| By Ben Nadel | Article Rating: |
|
| July 31, 2007 08:00 PM EDT | Reads: |
28,618 |
One of the most exciting features of the new ColdFusion 8 image manipulation is the large number of file formats that can be read in and written out. To give you insight into what is available, ColdFusion 8 has provided two methods: GetReadableImageFormats() and GetWriteableImageFormats(). These return comma-delimited lists of the file types that ColdFusion can deal with.
Calling GetReadableImageFormats() returns:
BMP, GIF, JFIF, JPEG, JPEG 2000, JPEG-LOSSLESS, JPEG-LS, JPEG2000, JPG, PNG, PNM, RAW, TIF, TIFF, WBMP
Calling GetWriteableImageFormats() returns:
BMP, GIF, JFIF, JPEG, JPEG 2000, JPEG-LOSSLESS, JPEG-LS, JPEG2000, JPG, PNG, PNM, RAW, TIF, TIFF, WBMP
Notice that ColdFusion 8 can handle GIF images! Super sweet! I don't know how they handled that one (since I thought Prodigy owned the patent on that or something silly), but it's good to see that we have a huge variety of image formats that we can read and write to.
Now that we have a general overview of what kind of new and exciting image manipulation features are available in ColdFusion 8 and how many image types can be utilized, let's get into the meat of this part of the tutorial: reading and writing images. To start with, let's examine reading images using the CFImage tag. When reading in an image, the source of the image can be any one of the following:
- Absolute path name
- Path name relative to the Web root
- URL
- CFImage variable
- BLOB / Byte array
- Base64 encoded image data
- Binary object
Did anyone else see "URL" and get mentally turned on? 'Cause I did...but, let's not get ahead of ourselves. I want to quickly explore these different source type values and, to do so, I am going to use the INFO action of the CFImage tag. In the first example we are using the CFImage tag in conjunction with an absolute path name to the image.
<!---
Read in the image file. This will read in the binary
image into an object of coldfusion.image.Image.
--->
<cfimage
action="INFO"
source="#ExpandPath( './lady.jpg' )#"
structname="objImageInfo"
/>
<!---
The CFImage tag above stores the image information
into a struct, objImageInfo. Dump out this struct.
--->
<cfdump
var="#objImageInfo#"
label="CFImage : Info Read"
/>
This reads color information, source value, and dimensions into a struct. Running the above code, we get the following CFDump output shown in Figure 1.
The other input types give a similar output, so I won't show the CFDump, however, I will walk through the code. The next one on the list is the Web-relative path:
<!--- Read in the image using a web-relative path. --->
<cfimage
action="INFO"
source="./lady.jpg"
structname="objImageInfo"
/>
This gives us the same output, but the source attribute is "./lady.jpg".
The next input type is a URL (sha-wing!):
<!--- Read in the image using a URL. --->
<cfimage
action="INFO"
source="http://localhost/testing/cf8/lady.jpg"
structname="objImageInfo"
/>
This gives us the same output, but the source attribute is "http://localhost/testing/cf8/lady.jpg". When reading from a URL-based image, you have to be careful about the URL format. It's not just important that the resultant data is image data, it's also important that the last thing in the URL be the file name. For example, using a URL with this query string:
<!--- Read in the image using a URL. --->
<cfimage
action="INFO"
source="http://localhost/testing/cf8/lady.jpg?referrer=bennadel"
structname="objImageInfo"
/>
...will throw the ColdFusion error:
The com image format is not supported on this operating system. Use GetReadableImageFormats() and GetWriteableImageFormats() to see which image formats are supported.
Published July 31, 2007 Reads 28,618
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Ben Nadel
Ben Nadel has worked with ColdFusion for eight years and is a super ColdFusion enthusiast. He blogs regularly about all aspects of Web development on his personal site, http://www.bennadel.com, and does his best to give back to the ColdFusion community through online code demos and his "Ask Ben" blog posts. He is also a Certified Advanced ColdFusion MX7 developer and is one of the lead programmers at Nylon Technology.
![]() |
Michael 07/12/08 01:43:25 AM EDT | |||
The noisy ad is beyond annoying. |
||||
![]() |
Mike Ritchie 08/01/07 06:08:54 PM EDT | |||
I wonder if the CF team consulted with the developer of ImageCFC? It also was basically a wrapper for the underlying Java image functionality. Either way, this looks like an exceptionally useful tool. Do you need to instantiate the object using cfimage? Or is it possible to manipulate an image completely within cfscript? |
||||
![]() |
Sanjeev 07/15/07 10:07:34 PM EDT | |||
rename the CodFusion as ColdFusion ! |
||||
- Instant Professionalism Online Despite Yourself...with Ulitzer
- Plone and Drupal: Different Approaches, Different Results
- New Virus Targets Facebook, MySpace and Twitter Users
- Developing APIs for the Cloud
- Oracle Enhances Primavera P6 Enterprise Project Portfolio Management
- Top 20 Cloud Services Providers That Are Gaining Mind Share
- Amazon's VPC Opens the Door for Innovation and Enterprise Cloud Adoption
- Adobe and Barnes & Noble Join Forces to Standardize eBook Technology
- Drupal Tip to Enable Clean URLs on Mac OS
- Beyond Social Business Software
- Amartya Sen: The Idea of Justice
- Terrific New Social Media Research Study Means It’s Time for Small Business to Get with the Program
- Microsoft Expression Web Has Got Game
- Instant Professionalism Online Despite Yourself...with Ulitzer
- Zimbra on Ulitzer Topic Launched
- Plone and Drupal: Different Approaches, Different Results
- New Virus Targets Facebook, MySpace and Twitter Users
- Developing APIs for the Cloud
- Oracle Enhances Primavera P6 Enterprise Project Portfolio Management
- Mezeo CEO to Speak at 4th Cloud Computing Expo
- Excuse Me But Is That a Gazebo On Your Site?!
- Prolifics Offers Easy Transition to IBM Lotus Web Content Management
- Top 20 Cloud Services Providers That Are Gaining Mind Share
- Amazon's VPC Opens the Door for Innovation and Enterprise Cloud Adoption
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Drupal Content Management Platform Has Been Chosen By Ulitzer
- Drupal Creator Forms Company
- Hot Banana Sponsors Gilbane White Paper On Using Web CMS
- Nastel to Exhibit at SYS-CON's SOA World Conference & Expo
- Drupal CMS to Move to a Whole New Level
- Hot Banana Is First To Add Web Site Optimization, Marketing Automation To Its Web CMS
- Hot Banana Unveils Multilingual Web CMS Module
- Ektron's CMS400.NET Now Supports Macromedia ColdFusion, Microsoft ASP, JSP, and PHP
- Ulitzer’s Amazing First 30 Days in Public Beta
- Magnolia 2.0 Becomes First CMS to Support the Java Content Repository
- Hot Banana Grows Web CMS Client Base






























