<cffunction name="getFileObject" access="private"
hint="Loads a file into memory so it's ready for manipulation">
<cfargument name="filePath" type="string" required="yes"
hint="Absolute path the the file you'd like to load.">
<!--- Loading the file into memory--->
<cfset var result=CreateObject("java","java.io.File")>
<cfset result.init(filePath)>
<!---Return the file object to the caller function--->
<cfreturn result>
</cffunction>
<cffunction name="memberPicture" output="true"
hint="Turns a file into the correct size, color, and format for the
site.">
<cfargument name="sourcePath" type="string"
required="yes" hint="Absolute path to the source image">
<cfargument name="destPath" type="string" required="yes"
hint="Absolute path to the place you want to put the processed
image.">
<cfargument name="new_width" type="numeric" required="no"
default="220">
<!---Load class to hold the input image in--->
<cfset var
ImageIO=CreateObject("java","javax.imageio.ImageIO")>
<!---Load class to hold the output image--->
<cfset var
jbiDest=CreateObject("java","java.awt.image.BufferedImage")>
<!---Load class that will be transforming the
image--->
<cfset var
jatTransformer=CreateObject("java","java.awt.geom.AffineTransform")>
<!---Call our local function to create the input and
destination file streams--->
<cfset var jFileIn=getFileObject(sourcePath)>
<cfset var jFileOut=getFileObject(destPath)>
<!---Load the input file into the imageIO object--->
<cfset var jbiSource=ImageIO.read(jFileIn)>
<!---See how big the input file is--->
<cfset var jFileIn_height=jbiSource.getHeight()>
<cfset var jFileIn_width=jbiSource.getWidth()>
<!---Figure out the scales for our output file--->
<cfset var scale=ARGUMENTS.new_width/jFileIn_width>
<cfset var jFileOut_height=jFileIn_height * scale>
<cfset var jFileOut_width=ARGUMENTS.new_width>
<!---Create a place to put the destination image
object--->
<cfset
jbiDest.init(JavaCast("int",jFileOut_width),JavaCast("int",jFileOut_height),jbiSource.getType())>
<!---Tell the transformer object how we want to transform
the image--->
<cfset jatTransformer.setToScale(scale,scale)>
<!---User the transformer to transform the input file so
that it's ready to be outputted--->
<cfset
jbiDest.getGraphics().drawRenderedImage(jbiSource,jatTransformer)>
<!---Convert the image into a 'jpeg' format and save it
to the desired destination--->
<cfset ImageIO.write(jbiDest, "jpeg", jFileOut)>
</cffunction>