Description of "showresults.cfm"

The form data is POSTed to "showresults.cfm" which saves the file using the Cold Fusion <cffile> tag. The check box is read so that the UnOptimize method can be called if required.

The GIF is saved to a temporary file so that it can be read by csASPGif.

The code to save the file, load it into csASPGif and extract the frames is all before the first HTML tag:

<cfobject action="create" name="Gif" class="csASPGifTrial.Gif">
<cfset CurrentDir=ExpandPath("./images/")>
<cftry>
<cffile action="upload" destination=#CurrentDir# filefield="filesent" accept="image/gif" nameconflict="MakeUnique">
<cfset SavedFile=CurrentDir & cffile.ServerFile>
<cfset Gif.ReadFile(SavedFile)>
<cfparam name="form.unoptimize" default="false">
<cfif form.unoptimize EQ "true">
  <cfset Gif.UnOptimize()>
</cfif>

<cfset TempName=CreateUUID()>
<cfset GIFPath=CurrentDir & TempName & ".gif">

<cfset LoopMax= Gif.FrameCount - 1>
<cfloop index="I" from="0" to=#LoopMax#>
<cfset tempfile=CurrentDir & tempname & I & ".gif">
<cfset Gif.WriteFrameToFile(TempFile, (I))>
</cfloop>

<cfcatch></cfcatch>
</cftry>

Errors will be generated if no GIF is supplied or if the file is unreadable. To ensure graceful failure a <cftry> tag is used around the code.

The next working part of the script is in the body of the page. The frame count and colour depth is extracted and displayed. Then each frame is displayed using a loop.

<cfif Gif.FrameCount EQ 0>
<p>No image loaded.</p>
<cfelse>
<p>Frame count: <cfoutput>#Gif.FrameCount#</cfoutput>.</p>
<p>Colour Depth: <cfoutput>#Gif.ColorDepth#</cfoutput>.</p>
<table>

<cfloop index="I" from="0" to=#LoopMax#>
<tr><td>Frame <cfoutput>#I#</cfoutput></td>
<td><img src="gifstream.cfm?Frame=<cfoutput>#I#&UUID=#tempname#</cfoutput>"</td></tr>
</cfloop>
</table>
</cfif>

The loop writes out an <img> tag for each frame in the GIF. The SRC attribute is another CFM script that streams the frame specified by the query string parameter.

<cfcache action="flush">
<cfset CurrentDir=ExpandPath("./images/")>
<cfset tempfile=CurrentDir & Url.UUID & Url.Frame & ".gif">
<cfcontent type="image/gif" deletefile="yes" file=#tempfile#>

Each frame had already been saved by results.cfm, and so it is simply a matter of streaming the appropriate frame and deleting the file.

There is a further description of the demo in the ReadMe.txt file supplied with the scripts.

Click Here to return to the start.