Description of "showexif.cfm"

The form data is POSTed to "showexif.cfm" which uses Cold Fusion's <cffile> tag to save the file. A temporary name is generated by using the CreateUUID() function. This file is then read into csImageFile, resized and saved again.

Some error control is required and so some Boolean variables are set in various places to indicate success or failure. They are then used further down the page to produce conditional HTML output. For example, if the file is not a JPEG it will be saved but an error will be generated when csImageFile attempts to read it. When an error occurs the temporary file is deleted.

The resize operation fits the image to an overall size defined by the "height" and "width" variables. Changing these values would resize the image to a different size.

Below is the code that extracts the EXIF attributes:

<cfset currentdir=ExpandPath("./")>
<cfset tempname=CreateUUID()>
<cfset tempfile=CurrentDir & tempname & ".jpg">
<cfset success=false>
<cfset nofile=false>
<cfset imageerror=false>
<cfif Len(form["filesent"]) LT 4>
  <cfset nofile=true>
<cfelse>
  <cffile action="upload" filefield="filesent" destination=#tempfile#>
  <cfset ext=form["filesent"]>
  <cfobject action="create" name="image" class="csImageFile.Manage">
  <cftry>
    <cfset image.ReadFile(#tempfile#)>
    <cfset success=true>
    <cfset oldsize=image.FileSize>
    <cfset width=200>
    <cfset height=200>
    <cfif (image.Width GT width) or (image.Height GT height)>
      <cfif (image.Width / width) GT (image.Height)>
        <cfset image.Resize(width, 0)>
      <cfelse>
        <cfset image.Resize(0, height)>
      </cfif>
    </cfif>
    <cfset image.WriteFile(#tempfile#)>
    <cfcatch>
      <cfset imageerror=true>
      <cffile action="delete" file=#tempfile#>
    </cfcatch>
  </cftry>
</cfif>
<html>
<head>
<title> . . .

The code which displays the EXIF data is shown below.

<cfif image.ExifCount EQ 0>
  No EXIF data in the image.
<cfelse>
  <b><u>EXIF Data:</u></b><br>
  <cfset loopto=image.ExifCount - 1>
  <cfloop index="I" from="0" to="#loopto#" step="1">
    <cfoutput>#image.ExifName(I)#</cfoutput> :
    <cfoutput>#image.ExifValueByIndex(I)#</cfoutput><br>
  </cfloop>
</cfif>

The image is displayed using "showexifimage.cfm". This script is shown below.

<cfcache action="flush">
<cfset currentdir=ExpandPath("./")>
<cfset filename=currentdir & url["name"] & ".jpg">
<cfcontent type="image/jpeg" deletefile="yes" file=#filename#>

The purpose of this script is simply to stream the image to the browser and delete the temporary file. The file name is passed in the URL.

Click Here to return to the upload form.

Click Here for an explanation of writing EXIF attributes.