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.

ColdFusion devcamp in San Francisco Nov. 7th, 2009

Sign up for cfdevcamp in San Francisco November 7th 2009.

cfdevcamp is a gathering of people passionate about learning through collaboration. Attendees will work in small teams to code projects ideas from the team members or from a suggested list of projects. This will not be a lecture style event or a traditional classroom with a set curriculum and learning materials. We want you to ask questions, hack away and have fun.

This is a great event for ColdFusion beginners, experts, and everyone in between.

For more information and to sign up for this free event visit: www.cfdevcamp.org

ColdFusion Security at Sacramento ColdFusion User Group Oct. 13, 2009

Join the Sacramento ColdFusion User Group Oct. 13, 2009 for a presentation on how to secure your ColdFusion applications and server. We will cover a broad range of topics from preventing SQL injection and cross site scripting attacks, to form validation, server settings, and more.

We will also be doing one of our giant Adobe software giveaways...

More info and directions here: www.saccfug.com

Sean Corfield and Railo at Sacramento ColdFusion User Group

Join the Sacramento ColdFusion User Group on Tuesday June 9th 2009 for Sean Corfield who will be speaking about Railo's CFML engine.

For more details on the meeting visit the SacCFUG website.

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

 

Edmund Event-Driven Framework At SacCFUG

Join the Sacramento ColdFusion User Group Tuesday Feb. 10, 2009 for a presentation on the "Edmund" Event-Driven Framework by Patrick Santora.

For more details on the meeting visit the SacCFUG website.

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

ColdBox Presentation at Sacramento ColdFusion User Group

Join the Sacramento ColdFusion User Group on January 13th 2009, Matt Graf will be talking about the ColdBox ColdFusion framework.

For more details and directions visit www.saccfug.com

Introduction to MVC at November Sacramento ColdFusion User Group

Sacramento ColdFusion User Group meets November 11th, this month Nolan Erck will be giving a presentation on "Introduction to Model View Controllers in ColdFusion". He will go over the basics of what MVC does, pros and cons, and give an introductory look at some code that uses this pattern.

This will be a non-framework-specific talk. No prior knowledge of Model-Glue, Mach-ii, etc required; none of the code samples will use a framework. However, some basic knowledge of CFCs will probably help tremendously

For more information and directions visit www.saccfug.com

More Entries