you can't inline image bytes with other character-based content...
that's the whole purpose of the <img /> tag. I'm not sure why you think
using a separate .cfm to push down the image is introducing disk
activity... once CF parses your .cfm into a servlet it's pretty much in
memory AFAIK, especially if hit often. Your second approach is the
correct (and only) way to do it.

-Dave

>>> [EMAIL PROTECTED] 10/06/05 3:32 AM >>>
Hi,

I'm trying to work out a way to cache binary image data in an
application
scoped CFC and output it directly to the output stream without needing
to
hit the hard disk at all. The objective is to tweak all the performance
i
can get out of a server.

Here's what i've got so far:

--
ImageCache.cfc
------------------------------------------------------------

<cfcomponent displayname="ImageCache">

        <cffunction name="init" access="public" returntype="ImageCache"
output="false">
                <cfargument name="imagePaths" required="Yes"
type="string" hint="Comma
delimited list of fully qualified paths to directories with images to
cache
in memory" />
                <cfset variables.imagePaths =
listToArray(arguments.imagePaths) />
                <cfset cacheImageData() />
                <cfreturn this />
        </cffunction>

        <cffunction name="cacheImageData" access="private"
returntype="void"
output="false">
                <cfset var imagePath = "" />
                <cfset var imageNames = "" />
                <cfset var imageKey= "" />
                <cfset var binImage = 0 />
                <cfloop from="1" to="#arrayLen(variables.imagePaths)#"
index="i">
                        <cfdirectory action="LIST"
directory="#variables.imagePaths[i]#"
name="imageNames" />
                        <cfloop query="imageNames">
                                <cfif
ListContains("gif,jpg,jpeg,png,bmp",ListLast(imageNames.name,
"."))>
                                        <cffile action="readBinary"
file="#variables.imagePaths[i]##imageNames.name#" variable="binImage">
                                        <cfset imageKey =
Replace(imageNames.name, ".","","all") />
                                        <cfset
variables[imageKey]['data'] = binImage />
                                        <cfset
variables[imageKey]['type'] = ListLast(imageNames.name, ".") />
                                </cfif>
                        </cfloop>
                </cfloop>
        </cffunction>

        <cffunction name="getImage" access="public" returntype="any"
output="false">
                <cfargument name="imageName" required="Yes"
type="string" />
                <cfset var imageKey = Replace(arguments.imageName,
".","","all") />
                <cfset var image = "missing" />

                <cfif StructKeyExists(variables,imageKey)>
                        <cfsavecontent variable="image">
                                <cfcontent
type="image/#variables[imageKey]['type']#" reset="No"
variable="#variables[imageKey]['data']#">
                        </cfsavecontent>
                </cfif>
                <cfreturn image />
        </cffunction>

</cfcomponent>
----------------------------------------------------------------------------

-- imageCacheTest.cfm --

<cfif NOT StructKeyExists(application, "ImageCache") OR
StructKeyExists(url,
"reset")>
        <cfset currentDirectory =
GetDirectoryFromPath(GetTemplatePath())>
        <cfset application.ImageCache =
createObject('component','ImageCache').init(currentDirectory)>
</cfif>

<cfoutput>
Other content???

#application.ImageCache.getImage('adminGreen.gif')#

</cfoutput>
----------------------------------------------------------------------------

What's happening is that the cfcontent tag in the CFC is preventing any
other content from being displayed on imageCacheTest.cfm

I do have something working, but it involves introducing a small hit to
the
hard disk like so.

-- image.cfm
---------------------------------------------------------------

<cfoutput>
#application.ImageCache.getImage(url.image)#
</cfoutput>
----------------------------------------------------------------------------

-- imageCacheTest2.cfm
----------------------------------------------------

<cfif NOT StructKeyExists(application, "ImageCache") OR
StructKeyExists(url,
"reset")>
        <cfset currentDirectory =
GetDirectoryFromPath(GetTemplatePath())>
        <cfset application.ImageCache =
createObject('component','ImageCache').init(currentDirectory)>
</cfif>

Other content???

<img src="image.cfm?image=arrows_small.gif" alt="" border="0" />

----------------------------------------------------------------------------

My thinking is that this may help under load, because it minimizes the
hit
to the hard disk, but i'd like to eliminate it completely.

Anyone have any suggestions?

thanks,
Nando





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of
the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to