This may not be the perfect solution, but it works...

I multiplied the Y Offset value by .95 and it centers close enough (or close
enough for government work as they say hehehe) across the font sizes we use
(16-30)...YAY!  Thank for your help!!!!

Eric

<cfcomponent
    output="false"
    hint="Image utility functions that abstract out complex ColdFusion image
manipulation processes.">
    <cffunction name="img_create_banner" access="public" output="true"
returntype="Any"
            hint="Creates banner grapic with custom text">
        <cfargument name = "text"      type = "string" required="true">
        <cfargument name = "fontname"      type = "string" required="true">
        <cfargument name = "style"      type = "string" required="true"
hint="Must be Plain, Bold, Italics, or Bolditalics">
        <cfargument name = "size"      type = "string" required="true"
hint="Font size in pixels">
        <cfargument name = "color"      type = "string" required="true"
hint="hex value with put pound sign">
        <cfargument name = "bgcolor" type = "string" required="true"
hint="hex value with put pound sign">
        <cfargument name = "path"      type = "string" required="true"
hint="local path to where image is to be saved">
        <cfargument name = "name"      type = "string" required="true"
hint="image name with extention">
        <cfscript>
            Font = CreateObject("java", "java.awt.Font");
            variables.color="##"&arguments.color;
            variables.bgcolor="##"&arguments.bgcolor;
            variables.style=arguments.style;
            variables.fontname="#trim(arguments.fontname)#";
            variables.text={x=10, y=30, string=arguments.text};
            variables.text.prop={font = variables.fontname,
Size=arguments.size, style=variables.style, javaStyle= BitOr(Font.BOLD,
Font.ITALIC), txtColor=variables.color, bgColor=variables.bgcolor};
            variables.imageOffset={x=20, y=10};
            // create a new image and draw the text
            img = ImageNew("", 10, 30, "rgb", arguments.bgcolor );
            // get the underlying graphic of the image
            graphics = ImageGetBufferedImage( img ).getGraphics();
         </cfscript>
            <!--- Check for a defined style. --->
         <cfswitch expression="#variables.text.prop.style#">
               <cfcase value="Bold">
                   <cfset variables.text.prop.javastyle = Font.BOLD>
            </cfcase>
            <cfcase value="Italic">
                   <cfset variables.text.prop.javastyle = Font.ITALIC>
            </cfcase>
            <cfcase value="BoldItalic">
                  <cfset variables.text.prop.javastyle =
BitOR(Font.BOLD,Font.ITALIC)>
            </cfcase>
            <!--- Otherwise, just use the default PLAIN style --->
            <cfdefaultcase>
                <cfset variables.text.prop.javastyle = Font.PLAIN>
            </cfdefaultcase>
          </cfswitch>
          <cfscript>
               // recreate the font used to draw the text
            CurrentFont = Font.init( javacast("string",
variables.text.prop.font),
            javacast("int", variables.text.prop.javaStyle),
            javacast("int", variables.text.prop.size)         );
            // get text measurements using font metrics
               fontMetrics = graphics.getFontMetrics( CurrentFont );
            fontBounds = fontMetrics.getStringBounds( javacast("string",
variables.text.string), graphics );
            context = graphics.getFontRenderContext();
            img = ImageNew("", fontBounds.getWidth()+20,
fontBounds.getHeight()+10, "rgb", variables.text.prop.bgcolor);
            graphics = ImageGetBufferedImage( img ).getGraphics();
            ImageSetDrawingColor( img, variables.text.prop.txtColor );
            variables.OffsetVal.y=  (javacast("int", variables.text.y)/2 +
javacast("int",(fontBounds.getHeight())/2))*.95;
            variables.offsetVal.x=variables.text.x;
            ImageDrawText( img,
variables.text.string,variables.OffsetVal.x,variables.OffsetVal.y ,
variables.text.prop );
            //dimensions.xoffset=variables.OffsetVal.x;
            //dimensions.yoffset=variables.OffsetVal.y;
            //dimensions.type = "FontMetrics";
            //dimensions.width = fontBounds.getWidth();
            //dimensions.height = fontBounds.getHeight();
            //dimensions.height_int =
javacast("int",fontBounds.getHeight());
            //dimensions.leading = fontMetrics.getLeading();
            //dimensions.ascent = fontMetrics.getAscent();
            //dimensions.descent = fontMetrics.getDescent();
               graphics.dispose();
        </cfscript>
        <!--- <cfdump var="#dimensions#"> --->
        <!--- <cfimage action="writeToBrowser" source="#img#">   --->
        <cfimage action="write" source="#img#" destination="#path#/#name#"
overwrite="true">

    </cffunction>
</cfcomponent>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:337089
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to