The ImageRead function performs the same operation as the cfimage read action . However, you cannot use the cfimage tag to read and create. You can use the cfimage tag to perform common image manipulation operations as a border; captcha; convert; info; read; resize; rotate; write; writeToBrowser. The other day, I needed to do some on-the-fly conversion of PNG image files to JPG format in ColdFusion. This was part of stop-gap measure at.
|Published (Last):||8 May 2004|
|PDF File Size:||16.41 Mb|
|ePub File Size:||20.43 Mb|
|Price:||Free* [*Free Regsitration Required]|
Cfikage, ColdFusion 8 has incorporated image manipulation directly into the ColdFusion tag and scripting language. No more are we, as developers, chained to third-party products.
These products, while excellent in quality, just mean adding one more level of complexity to any application that requires server-side image manipulation. Now, with CFImage and an abundance of image-related functions, ColdFusion has done to image manipulation what it has done to almost every other aspect of Web applications development – it has made it simple.
Due to the wide array of image convsrt in ColdFusion 8, I am going to try and break this tutorial up into several small and manageable parts. The first part will cover basic reading and writing of images using CFImage and the related image manipulation functions. But, before we get into that, let’s just quickly touch upon these new features as a whole. ColdFusion 8 has given us CFImage. CFImage provides us with tag-based access to only a small subset of the image functionality cfiimage. In addition to the CFImage tag, ColdFusion has introduced dozens of new image manipulation functions including:.
Most of you cfimmage not going to care about this one all that much, but for those of you who are interested fcimage the underlying Java methods of the ocnvert.
Image object, I have listed them below skip past this if you have no idea what I’m talking about. If you choose to use them, you do so at your own risk and discretion. For those of you who took a look at the underlying Java methods, you convfrt see that there’s a lot of stuff wrapped up in these image objects.
The ColdFusion 8 CFImage tag and the related image manipulation functions probably provide some sort of facade that wraps around the underlying methods. Covnert more information about what these do as they cfijage undocumentedtry exploring the java. Ben Forta stated at the New York ColdFusion Users group that Adobe has built the ColdFusion image manipulation around this library, but that they have also greatly extended it to work around the limits that this library holds.
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: These return comma-delimited lists of the file types that ColdFusion can deal with.
I don’t know how they handled that one since I thought Prodigy owned the patent on that or something sillybut 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 cfimabe utilized, let’s get into the meat of this part of the tutorial: 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:.
Did anyone else see “URL” and get mentally turned on? In the first example we are using the CFImage tag in conjunction with an absolute path name to the image.
converr This will read in the binary image into an object of coldfusion. Dump out this struct. This crimage 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:. This gives us the same output, but the source attribute is “http: 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:.
The com image format is not supported on this operating system. This will only work to direct image URL access. This seems like a bug to me as I would convegt assumed it was just doing a binary grab via CFHttp or something like thatfcimage I guess there is more to it than I can understand.
I would rather it try to grab the resultant data and throw an converr if the read fails. This will work quite nicely. 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 cfimagd new images; we can perform them on existing image objects:.
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:. The next input type is a Base64 encoded string.
This doesn’t mean the target file is a Base64 data text file – this means the actual input value is Base64 image data:. To get Base64 image data, we can convert the binary read we did above. I don’t deal with Base64 encoded images all that often, but this seems convett 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.
Converting an image to grayscale using the CFIMAGE tag in ColdFusion | ColdFusion Examples
If you want to actually read the image into a ColdFusion variable in the form cfimsge the coldfusion. Image data typeuse the action “READ”:. 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. When it comes to functions, if you want to read in Base64 image data, you have to use the ImageReadBase64 function:.
In addition to these straightforward methods, ColdFusion 8 can also use the ImageNew function cfmage read in images. Like the methods and tags above, ImageNew can also take a variety of source types:. We have looked at most of these types above. The only one here that stands out is the Java buffered image. This is the object that the ColdFusion image is wrapped around and is exposed through the function ImageGetBufferedImage. To demonstrate this, we can grab the buffered image of one image object and use it to instantiate a new image:.
This kind of functionality can be super useful if you are interfacing with another Java component that handles image manipulation using the java. That just about wraps up reading in image files. Let’s quickly cover writing images. As with reading in images, writing them can be done by using the CFImage tag as well as the image functions. The CFImage tag makes writing files especially easy since the source attribute is so flexible. Here, we are going to read an image from a URL and save it to disk:.
Notice that the destination path is not an absolute server path – it’s a path relative to the current Web page. Also notice that the destination image was a GIF file format. By default ColdFusion will throw an error if there are naming conflicts. To overcome this, you can set the Overwrite attribute to true defaults to false – this will overwrite any existing files of the same name.
Now, not only is it super easy to grab images, it’s super easy to converh image types. This also demonstrates our next mode of image writing: Notice that to do this, I am specifying the source of the image the image object we created and the output format of JPG. Now, when I first saw this action, I had assumed it was working the same way CFContent convedt – by streaming the file to the browser as the only returned content.
ColdFusion Help | Converting images
However, WriteToBrowser actually returns the image inline to the page. If you look at the source of the page with the rendered inline image, you will see something like this:. ColdFusion is actually writing your file to some sort of temporary image storage and then serving it up the way any other image or file would be served convfrt. But what is CFFileServlet?
If I look in the root of my ColdFusion 8 test account, there is no such directory. This is some sort of public mapping, but realize this – this is not a ColdFusion request; this is an image file request.
Image file requests go the Web server, not the ColdFusion application server. This makes me nervous. I think it’s an awesome feature, but I’m not sure I like having to rely on mappings and tying in with settings external to the ColdFusion application server. On the flip side, however, I do like this for the very reason that the image request is not going to the ColdFusion server.
Storing an image to a temp directly and then serving it using the Web server is going to be 10 times more efficient. I would like to know more about how CFFileServlet works and specifically how often that directory is cleaned out.
I don’t want to start writing a lot of images to the browser only to find out that it is clogging up this temp directory.
Converting an image to grayscale using the CFIMAGE tag in ColdFusion
When it comes to writing images using ColdFusion 8 image functions, there are basically two options: ImageWrite convwrt three arguments potentially:. As you can see, since we are grabbing the image via a URL, we must include the destination value. I have also included the JPG quality value, but this was not necessary as that value defaults to. It takes four arguments:.
Just a final note on paths; the Web-relative path e. Therefore, if you are in an included template, you might get files stored in unexpected places if you don’t fully grasp this concept.