Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 00:52
Show Gist options
  • Save bennadel/9753072 to your computer and use it in GitHub Desktop.
Save bennadel/9753072 to your computer and use it in GitHub Desktop.
Trimming An Image Canvas With ImageUtils.cfc ColdFusion Image Component
<!--- Create the image utils object. --->
<cfset objImageUtils = CreateObject(
"component",
"imageutilsroot.imageUtils"
).Init()
/>
<!--- Create a large, off-white canvas. --->
<cfset objImage = ImageNew(
"",
300,
300,
"argb",
"##F5F5F5"
) />
<!--- Set the drawing color. --->
<cfset ImageSetDrawingColor(
objImage,
"##FF9900"
) />
<!--- Draw a circle in the middle of the canvas. --->
<cfset ImageDrawOval(
objImage,
100,
100,
100,
100,
"yes"
) />
<!--- Set up our font properties. --->
<cfset objFont = {
Size = "20",
Font = "Arial Black"
} />
<!--- Draw text. --->
<cfset ImageDrawText(
objImage,
"MY FIRST CIRCLE",
45,
250,
objFont
) />
<p>
<!--- Write image to browser. --->
<cfimage
action="writetobrowser"
source="#objImage#"
/>
</p>
<!--- Trim the canvas. --->
<cfset objImage = objImageUtils.TrimCanvas(
objImage,
"##F5F5F5"
) />
<p>
<!--- Write image to browser. --->
<cfimage
action="writetobrowser"
source="#objImage#"
/>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment