ImageDrawText Coordinates
February 25, 2008 9:35 AM
Related Categories: Web Dev
This was probably clear to other people, but the coordinates for ImageDrawText were a bit counter intuitive for me. I expected that drawing text to 0,0 would have my text shown fully at the top left of the image. Point 0,0 would be the top and left point of my text.
However the text is rendered from the bottom,left point of your text area. Thus setting coordinate 0,0 would usually result in most of the text being drawn above canvas. So if you want your text to show up fully in the top left area, simply make an offset the size of the font size (default of 10).
As an example see this page running the code below.
<!--- 0,0 --->
<cfset myImage=ImageNew("",200,100)>
<cfset ImageSetDrawingColor(myImage,"green")>
<cfset ImageDrawText(myImage,"It's not easy being green.",0,0)>
<cfimage source="#myImage#" action="writeToBrowser">
<!--- 0,10 --->
<cfset myImage2=ImageNew("",200,100)>
<cfset ImageSetDrawingColor(myImage2,"green")>
<cfset ImageDrawText(myImage2,"It's not easy being green.",0,10)>
<cfimage source="#myImage2#" action="writeToBrowser">
<!--- 0,20 --->
<cfset myImage3=ImageNew("",200,100)>
<cfset ImageSetDrawingColor(myImage3,"green")>
<cfset ImageDrawText(myImage3,"It's not easy being green.",0,20)
<cfimage source="#myImage3#" action="writeToBrowser">
<cfset myImage=ImageNew("",200,100)>
<cfset ImageSetDrawingColor(myImage,"green")>
<cfset ImageDrawText(myImage,"It's not easy being green.",0,0)>
<cfimage source="#myImage#" action="writeToBrowser">
<!--- 0,10 --->
<cfset myImage2=ImageNew("",200,100)>
<cfset ImageSetDrawingColor(myImage2,"green")>
<cfset ImageDrawText(myImage2,"It's not easy being green.",0,10)>
<cfimage source="#myImage2#" action="writeToBrowser">
<!--- 0,20 --->
<cfset myImage3=ImageNew("",200,100)>
<cfset ImageSetDrawingColor(myImage3,"green")>
<cfset ImageDrawText(myImage3,"It's not easy being green.",0,20)
<cfimage source="#myImage3#" action="writeToBrowser">
Like this entry? Subscribe to my blog.


Comments (moderation on)
There are no comments for this entry.
[Add Comment]