Viewing Camera RAW Images with ColdFusion
This example demonstrates how to open/save/view Camera RAW images with ColdFusion and jrawio. jrawio is a Service Provider Implementation for the java ImageIO it provides the ability to read camera raw image formats such as Canon CR2/CRW and Nikon NEF. Check the jrawio site for a list of currently supported cameras.
Setup jrawio
The first step is to download the jrawio binary.
Take the jar (it.tidalwave.imageio.raw-[version].jar) and place it in ColdFusion's "\lib\" directory.
Read RAW image and write to JPG
This first example reads a camera raw file and converts it to a JPG and writes it to a file. The benefit of writing the file as a JPG is that this process is relatively fast.
<cfscript>
//input file
filename = expandPath("CRW_3933.CRW");
fileio = createObject("Java","java.io.File").init(filename);
//read RAW
imageio = createObject("Java","javax.imageio.ImageIO").read(fileio);
//write jpg
outname = expandPath("CRW_3933.jpg");
output = createObject("Java","java.io.File").init(outname);
createObject("Java","javax.imageio.ImageIO").write(imageio, "jpg", output);
</cfscript>
Read RAW image, resize, and writetobrowser
This next example reads a camera raw image, resizes the image to a thumbnail, then writes that image to browser. Warning this can be very slow.
<cfscript>
//input file
filename = expandPath("CRW_3933.CRW");
fileio = createObject("Java","java.io.File").init(filename);
//read RAW
imageio = createObject("Java","javax.imageio.ImageIO").read(fileio);
//resize
imageWidth = 200;
imageHeight = 200;
scaledImage = imageio.getScaledInstance(JavaCast("int", imageWidth), JavaCast("int", imageHeight), imageio.SCALE_FAST);
bufferedImage = createObject("java", "java.awt.image.BufferedImage").init(JavaCast("int", imageWidth), JavaCast("int", imageHeight), imageio.TYPE_INT_RGB);
graphics = bufferedImage.createGraphics();
graphics.drawImage(scaledImage, 0, 0, Javacast("null", ""));
//create cfimage from buffered image
cfimage = imageNew(bufferedImage);
</cfscript><cfimage action="writeToBrowser" source="#cfimage#">
Can be slow...
Be aware that processing of RAW images can be very slow and processor intensive. For example the second code sample may take 10-30 seconds with a large raw image.


