| By Ben Nadel | Article Rating: |
|
| July 31, 2007 08:00 PM EDT | Reads: |
28,618 |
The problem here is that ColdFusion is not recognizing the query string of the URL. This also means that you can't grab URLs that are served by ColdFusion using CFContent. This will only work to direct image URL access. This seems like a bug to me as I would have assumed it was just doing a binary grab via CFHttp (or something like that), but I guess there is more to it than I can understand. I would rather it try to grab the resultant data and throw an exception if the read fails.
Of course, there is a hack to get around this: you can add the image format to the query string:
http://localhost/testing/cf8/lady.jpg?referrer=bennadel&type=.jpg
This will work quite nicely. You get the idea here that ColdFusion is just doing some sort of ListLast() type functionality on the URL to get the file extension. A bit of a hack, but it works if you need it to.
The next input type is a ColdFusion image object. We don't have to perform actions just on new images; we can perform them on existing image objects:
<!--- Read the image into ColdFusion memory. --->
<cfimage
action="READ"
source="#ExpandPath( './lady.jpg' )#"
name="objImage"
/>
<!--- Get the image info from the existing image. --->
<cfimage
action="INFO"
source="#objImage#"
structname="objImageInfo"
/>
The next input type is the BLOB (Binary Large Object Bitmap) and the byte array. I am grouping these two together because I am sure what the difference really is. To me, they are both binary objects (I think). I don't generally deal with these sorts of objects:
<!--- Read in the binary image data. --->
<cffile
action="READBINARY"
file="#ExpandPath( './lady.jpg' )#"
variable="binImage"
/>
<!--- Read the binary directly into an image object. --->
<cfimage
action="INFO"
source="#binImage#"
structname="objImageInfo"
/>
When you read in an image in this fashion, the source attribute is empty.
The next input type is a Base64 encoded string. The CFImage tag has the boolean attribute, IsBase64, which flags the input as being Base64 data. This doesn't mean the target file is a Base64 data text file - this means the actual input value is Base64 image data:
<!--- Read in the binary image data. --->
<cffile
action="READBINARY"
file="#ExpandPath( './lady.jpg' )#"
variable="binImage"
/>
<!---
Read in the Base64 image data. To get Base64 image
data, we can convert the binary read we did above.
--->
<cfimage
action="INFO"
source="#ToBase64( binImage )#"
structname="objImageInfo"
isbase64="true"
/>
I don't deal with Base64 encoded images all that often, but this seems like something that could be very useful when put into clever hands. When you read in an image in this fashion, the source attribute is empty. The Base64 data does not require headers to be used.
For all the above "Read" demos, we were really just getting the info about the image. If you want to actually read the image into a ColdFusion variable (in the form of the coldfusion.image.Image data type), use the action "READ":
<!--- Read image into memory. --->
<cfimage
action="READ"
source="#ExpandPath( './lady.jpg' )#"
name="objImage"
/>
While this reads the image into memory, if you CFDump it out, you'll get the same output as if you were dumping out the INFO action result.
Now that we have covered the tag-based reading, let's examine reading in images using the new ColdFusion 8 image functions. To start with, let's look at ImageRead(). Like the CFImage tag, the ImageRead() function can take a variety of source types:
- Absolute path name
- Web relative path name
- URL
The ImageRead() function takes this is as the only argument:
<!--- Read in the image using an absolute path. --->
<cfset objImage = ImageRead(
ExpandPath( "./lady.jpg" )
) >
<!--- Read in the image using a web-relative path. --->
<cfset objImage = ImageRead(
"./lady.jpg"
) >
<!--- Read in the image using a URL. --->
<cfset objImage = ImageRead(
"http://localhost/testing/cf8/lady.jpg"
) />
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





























