Description of "showiptc.cfm"

The form data is POSTed to "showiptc.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.

<cfset tempname=CreateUUID()>
<cfset tempfile=ExpandPath(".") & "\" & 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> . . .

Some of the code which displays the IPTC meta data is shown below.

<cfif image.HasFileInfo EQ false AND image.HasXMP EQ false>
  No IPTC text in the image.
<cfelse>
  <p>IPTC text:<br>
  <cfif Image.FFO_Caption NEQ "">
    Caption: <cfoutput>#HTMLEditFormat(Image.FFO_Caption)#</cfoutput><br>
  </cfif>
  <cfif Image.FFO_CaptionWriter NEQ "">
    Caption Writer: <cfoutput>#HTMLEditFormat(Image.FFO_CaptionWriter)#</cfoutput><br>
  </cfif>
  <cfif Image.FFO_Headline NEQ "">
    Headline: <cfoutput>#HTMLEditFormat(Image.FFO_Headline)#</cfoutput><br>
  </cfif>

  <cfif Image.FFO_DateCreated NEQ 0>
    Date Created: <cfoutput>#DateFormat(Image.FFO_DateCreated)#</cfoutput><br>
  </cfif>
  Copyright Flag: <cfoutput>#Image.FFO_CopyrightFlag#</cfoutput><br>
  <cfif Image.FFO_KeywordsCount GT 0>
    Keywords:
    <cfset loopto = Image.FFO_KeywordsCount - 1>
    <cfloop index="I" from="0" to="#loopto#" step="1">
      <cfoutput>#Image.FFO_Keywords(I)# </cfoutput>
    </cfloop><br>
  </cfif>
  <cfif Image.FFO_SuppCatCount GT 0>
    Supplemental Categories:
    <cfset loopto = Image.FFO_SuppCatCount - 1>
    <cfloop index="I" from="0" to="#loopto#" step="1">
      <cfoutput>#Image.FFO_SuppCat(I)# </cfoutput>
    </cfloop><br>
  </cfif>
  Urgency: <cfoutput>#Image.FFO_Urgency#</cfoutput></p>
</cfif>

Each meta data attribute supported has its own property. Most are string values and only the first three are shown here. The Keywords and SupplementalCategories are lists of values and they are displayed by looping through the list.

Click Here to return to the upload form.