Today's contest uses the new image manipulation routines in ColdFusion 8. The objective is to take the custom tag/template skeleton below and add to it so that it'll generate the following image:
The tag/template can be invoked as a custom tag, or directly on the URL with URL and/or form parameters to set it's values. Just save it off to your CF8 instance and replace the "add your stuff here" with your code to build out the 'image' variable. Note that you have to center the text the "right" way, not just by figuring out the proper pixel offset from the top and left edges for the hard coded defaults. You can test this by supplying alternate text to render on the URL.
<cfif NOT isDefined("attributes")> <cfset attributes = structNew() /> <cfset structAppend(attributes, form, false) /> <cfset structAppend(attributes, url, false) /> </cfif> <cfparam name="attributes.width" default="100" /> <cfparam name="attributes.height" default="100" /> <cfparam name="attributes.backgroundColor" default="f7f7f7" /> <cfparam name="attributes.borderColor" default="cccccc" /> <cfparam name="attributes.textColor" default="990000" /> <cfparam name="attributes.text" default="Hello!" /> <cfset image = ... add your stuff here <cfimage action="writeToBrowser" source="#image#" />
Post your solutions in a comment. All correct submissions will get a congratulatory mention in my next post, and all submissions (correct or not) will get a one-line shout-out to whomever (generated by your own code ;), so make sure you supply your shout-out, name, and URL in your submission.
For extra credit, add this block below the last CFPARAM tag, pass the fontArgs struct as the fifth parameter to imageDrawText, and ensure everything still renders correctly.
<cfparam name="attributes.textSize" default="14" /> <cfparam name="attributes.textStyle" default="bolditalic" /> <cfparam name="attributes.textFont" default="courier" /> <cfset fontArgs = structNew() /> <cfif structKeyExists(attributes, "textSize") AND isNumeric(attributes.textSize)> Â <cfset fontArgs["size"] = attributes.textSize /> </cfif> <cfif structKeyExists(attributes, "textStyle") AND len(trim(attributes.textStyle)) GT 0> Â <cfset fontArgs["style"] = attributes.textStyle /> </cfif> <cfif structKeyExists(attributes, "textFont") AND len(trim(attributes.textFont)) GT 0> Â <cfset fontArgs["font"] = attributes.textFont /> </cfif>
Well, I've given up and it seems like no else did better, how about you post the solution here?
Brian,
I have posted the solution, one for each part.
http://www.barneyb.com/barneyblog/?s=wednesday