Ok, so I have a working solution that gives acceptable results - the final files are slightly smaller than my initial manual process, but visually indistinguishable.
The solution is not as cross-platform as we would like (you need to find / create a Linux binary for OptiPNG), but it is still a good enough solution.
, , , MapColorsFilter, , , , , OptiPNG .
:
<cfscript>
var Filename = './filename.png'
var MyImage = NewImage(Filename)
ImageFilter(MyImage,'quantize',{numColors:256,dither:false})
var TransImage = ImageMapColors(MyImage,'white','ffffff00')
ImageWrite( TransImage , Filename )
</cfscript>
<cfexecute
name = "#Variables.OptiPngExecutable#"
arguments = "-o9 #Filename#"
timeout = 30
/>
Railo ImageFilter MapColors, , , :
<cffunction name="ImageMapColors" output=false >
<cfargument name="Image" rtype="Image" required />
<cfargument name="Old" type="String" required />
<cfargument name="New" type="String" required />
<cfset var ObjKey = 'ColorReplacer_#Arguments.Old#_#Arguments.New#' />
<cfif NOT StructKeyExists(Variables,ObjKey)>
<cfset var Old = createObject('java','railo.commons.color.ColorCaster').toColor(Arguments.Old) />
<cfset var New = createObject('java','railo.commons.color.ColorCaster').toColor(Arguments.New) />
<cfset Variables[ObjKey] = createObject("java","railo.runtime.img.filter.MapColorsFilter")
.init(Old.getRGB(),New.getRGB()) />
</cfif>
<cfreturn ImageNew( Variables[ObjKey].filter(ImageGetBufferedImage(Arguments.Image),{}) ) />
</cffunction>