Leave That Thing Alone Blog

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.

CFCPhotoBlog Adds Railo Support

CFCPhotoBlog has been updated to support Railo

There were actually very few changes required to make Railo happy. The main problem was that I had used several Adobe ColdFusion specific cfform tags that were not really needed.

View a demo and download from CFCPhotoBlog project page

 

Retrieve Exif Metadata from Camera RAW and TIFF in ColdFusion 8

This example demonstrates how to get Exif metadata from Camera RAW and TIFF files in ColdFusion. In this sample I'm using a raw CR2 file from a Canon D30. Please note this example only reads RAW exif metdata, it does not read/process the RAW image

update: Viewing Camera RAW Images with ColdFusion

ColdFusion 8's image tags allow the retrieval of Exif metadata from only certain image types, ColdFusion actually uses Drew Noakes Metadata Extract library. There is now a beta version (metadata-extractor-2.4.0-beta-1.jar) that introduces code for processing camera RAW images and TIFF files.

One way to use this beta library is to go into the [coldfusion8]\lib\ folder and rename the 'metadata-extractor-2.2.2.jar' file to .bak then copy the latest metadata-extractor JAR file into that directory.

However, in this example i'm going to use Mark Mandel's JavaLoader so I can use the beta library separately from the stable version cfimage uses.

The code below reads a camera Raw image then iterates through all the metadata:

<cfscript>
	//read Canon RAW CR2 file
	photoFile = createObject("java","java.io.File").init("#expandpath('IMG_7913.CR2')#");
	//set the path
	paths[1] = "D:\test\metadata-extractor-2.4.0-beta-1.jar";
	//create the loader
	javaLoader = createObject("component", "JavaLoader").init(paths);
	//create the TiffMetadataReader instace
	tiffMetadataReader = javaLoader.create("com.drew.imaging.tiff.TiffMetadataReader");
	//read metadata
	metadata = tiffMetadataReader.readMetadata(photoFile);
	//get directories
	directories = metadata.getDirectoryIterator();
</cfscript>

<cfoutput> <table cellspacing="0"> <cfloop condition="directories.hasNext()"> <cfset currentDirectory = directories.next() /> <cfset tags = currentDirectory.getTagIterator() /> <cfloop condition="tags.hasNext()"> <cfset currentTag = tags.next()> <tr> <td valign="top">#currentTag.getTagType()#</td> <td style="vertical-align:top;width:150px;">#currentTag.getTagName()#</td> <td valign="top">#currentTag.getDescription()# </td> <td>#currentTag.getTagTypeHex()#</td> </tr> </cfloop> </cfloop> </table> </cfoutput>

Sample output:

coldfusion raw tiff exif

CFCPhotoBlog 1.1 Update

CFCPhotoBlog has been updated to version 1.1. Here is what is new:

This is not a huge update mainly I wanted a new look on my photoblog, so I added two new skins 'moderndark' and 'modernlight'. For fun I added support for cooliris/piclens, this adds a special RSS feed that allows cooliris to view the photos.

As always suggestions and feature requests are welcomed. I am planning now for version 2.0.

CFCPhotoBlog project page

Gumbo and Catalyst Photo Viewer Application

I've posted an example of a Flex application created with the MAX preview versions of Flash Catalyst and Gumbo. This small demo application was created to test out some of the new features in both Catalyst and Gumbo. It is not a perfect project, but a starting point for further projects.

Gumbo Catalyst Photo Application
View Example (right click for source)

The main goal of this project was to play with the new features in Catalyst and Gumbo using a close to real world example application, here is what was done:

  • Start with a photoshop layout (PhotoShop file located in PSD directory)
  • Use Catalyst to layout/components/skins and export FXG project
  • Import FXG to Gumbo project
  • In Gumbo add data/photo/etc functionality to the project
  • Take project back to Catalyst for small visual edits, then back to Gumbo
  • Use new Gumbo MXML tags/components
  • Play with new __AS3__.vec.Vector (using the new BitmapData.histogram)

Instead of detailing every step of the process there is great Gumbo Documentation and Catalyst Examples.

View Catalyst and Gumbo Photo Application (requires Flash 10 player)