Announcement

Collapse
No announcement yet.

MivaScript Gd Library: Font Rendering

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MivaScript Gd Library: Font Rendering

    Does the current version of the MivaScript graphics library render fonts, True Type or any other?

    If not, it seems I will still have to use PHP.
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

    #2
    Re: MivaScript Gd Library: Font Rendering

    From Dev:

    the functions needed are gdImageStringFT and gdImageStringFTCircle
    It should work on any modern linux, but the available fonts will differ, of course
    Thanks,

    Rick Wilson
    CEO
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: MivaScript Gd Library: Font Rendering

      Cool! Thanks Rick,

      I will experiment with those.
      Ray Yates
      "If I have seen further, it is by standing on the shoulders of giants."
      --- Sir Isaac Newton

      Comment


        #4
        Re: MivaScript Gd Library: Font Rendering

        I'm not able to get this to work.

        See http://dts2312.mivamerchantdev.com/m...geStringFT.mvc

        I get an error from the function gdImageStringFT() but can not determine the cause.
        It could be the font path, but I've tried many variations without success.

        The example in the docs shows this.
        char *f = "/usr/local/share/ttf/Times.ttf"; /* User supplied font */
        Which obviously wont work as a path so I put the .mvc in the same folder ast the font, without sucess.

        The docs also mention somthing called the FreeType library. Does this need to be installed?


        Code:
        <MvCOMMENT>    Test file: gdImageStringFT.mv
        
        
            Links:
                http://www.boutell.com/gd/manual2.0.33.html#gdImageStringFT
                http://www.mivascript.com/item/mivascript-functions/gdImageStringFT.html
                http://extranet.miva.com/forums/showthread.php?115047-MivaScript-Gd-Library-Font-Rendering
        
        
        
        
            gdImageStringFT( im, brect var, fg, fontlist, ptsize, angle, x, y, string )
                Parameters
                im =        Image the text will be appended to
                brect =     Array of the bounding rectangle surrounding the text
        
        
                            The user-supplied int brect[8] array is filled on return from gdImageStringFT
                            with the 8 elements representing the 4 corner coordinates of the bounding
                            rectangle (the smallest rectangle that completely surrounds the rendered
                            string and does not intersect any pixel of the rendered string).
        
        
                fg =        Font color
                fontlist =  Font family
                ptsize =    Font point size
                angle =     Angle in which the text is displayed. (Values accepted in radians)
                x =         The horizontal position of where the text will be written
                y =         The vertical position of where the text will be written
                string =    The text to be appended to the image
        
        
        </MvCOMMENT>
        
        
        <MvASSIGN NAME="g.module_library_utilities" VALUE="/mm5/5.00/lib/util.mvc">
        
        
        <MvCOMMENT> Create an image </MvCOMMENT>
        <MvASSIGN NAME="l.width" VALUE="180">
        <MvASSIGN NAME="l.height" VALUE="60">
        <MvASSIGN NAME="l.image" VALUE="{ gdImageCreate( l.width, l.height ) }">
        
        
        
        
        <MvCOMMENT> Set color (background = first allocated) </MvCOMMENT>
        <MvASSIGN NAME="l.bg" VALUE="{ gdImageColorAllocate( l.image, 200, 200, 240) }">
        <MvASSIGN NAME="l.fg" value="gdImageColorAllocate( l.image, 0, 0, 0 )" />
        
        
        <MvCOMMENT> Set the font Note </MvCOMMENT>
        <MvASSIGN NAME="l.font" VALUE="Nimbus Mono L:regular" />
        <MvASSIGN NAME="l.font" VALUE="times:bold:italic" />
        <MvASSIGN NAME="l.font" VALUE="Commercial Script.ttf" />
        
        
        <MvASSIGN NAME="l.ptsize" VALUE="12" />
        
        
        <MvASSIGN NAME="l.angle" VALUE="0" />
        <MvASSIGN NAME="l.x" VALUE="10" />
        <MvASSIGN NAME="l.y" VALUE="10" />
        
        
        <MvASSIGN NAME="l.text" VALUE="Ray Yates" />
        
        
        
        
        <MvASSIGN NAME="l.err" VALUE="{ gdImageStringFT( l.image, l.brect, l.fg, l.font, l.ptsize, l.angle, l.x, l.y, l.text ) }" />
        <MvASSIGN NAME="l.void" VALUE="{ [g.module_library_utilities].Image_gdSaveToFile_Type( l.image, 'png', '/temp.png', 'script' ) }">
        <MvASSIGN NAME="l.void" VALUE="{ gdImageDestroy( l.image ) }" />
        
        
        <!DOCTYPE html>
        <html>
        <head>
            <title>gdImageStringFT Test</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>
        <body>
        <MvEVAL EXPR="{ 'l.err = ' $ l.err $ ' <br>' }"><br>
        <img src="/temp.png"><br>
        
        
        </body>
        </html>
        Last edited by RayYates; 01-29-15, 08:14 AM.
        Ray Yates
        "If I have seen further, it is by standing on the shoulders of giants."
        --- Sir Isaac Newton

        Comment


          #5
          Re: MivaScript Gd Library: Font Rendering

          Originally posted by RayYates View Post
          I'm not able to get this to work.

          See http://dts2312.mivamerchantdev.com/m...geStringFT.mvc

          I get an error from the function gdImageStringFT() but can not determine the cause.
          It could be the font path, but I've tried many variations without success.

          The example in the docs shows this.
          char *f = "/usr/local/share/ttf/Times.ttf"; /* User supplied font */
          Which obviously wont work as a path so I put the .mvc in the same folder ast the font, without sucess.

          The docs also mention somthing called the FreeType library. Does this need to be installed?


          Code:
          <MvCOMMENT>    Test file: gdImageStringFT.mv
          
          
              Links:
                  http://www.boutell.com/gd/manual2.0.33.html#gdImageStringFT
                  http://www.mivascript.com/item/mivascript-functions/gdImageStringFT.html
                  http://extranet.miva.com/forums/showthread.php?115047-MivaScript-Gd-Library-Font-Rendering
          
          
          
          
              gdImageStringFT( im, brect var, fg, fontlist, ptsize, angle, x, y, string )
                  Parameters
                  im =        Image the text will be appended to
                  brect =     Array of the bounding rectangle surrounding the text
          
          
                              The user-supplied int brect[8] array is filled on return from gdImageStringFT
                              with the 8 elements representing the 4 corner coordinates of the bounding
                              rectangle (the smallest rectangle that completely surrounds the rendered
                              string and does not intersect any pixel of the rendered string).
          
          
                  fg =        Font color
                  fontlist =  Font family
                  ptsize =    Font point size
                  angle =     Angle in which the text is displayed. (Values accepted in radians)
                  x =         The horizontal position of where the text will be written
                  y =         The vertical position of where the text will be written
                  string =    The text to be appended to the image
          
          
          </MvCOMMENT>
          
          
          <MvASSIGN NAME="g.module_library_utilities" VALUE="/mm5/5.00/lib/util.mvc">
          
          
          <MvCOMMENT> Create an image </MvCOMMENT>
          <MvASSIGN NAME="l.width" VALUE="180">
          <MvASSIGN NAME="l.height" VALUE="60">
          <MvASSIGN NAME="l.image" VALUE="{ gdImageCreate( l.width, l.height ) }">
          
          
          
          
          <MvCOMMENT> Set color (background = first allocated) </MvCOMMENT>
          <MvASSIGN NAME="l.bg" VALUE="{ gdImageColorAllocate( l.image, 200, 200, 240) }">
          <MvASSIGN NAME="l.fg" value="gdImageColorAllocate( l.image, 0, 0, 0 )" />
          
          
          <MvCOMMENT> Set the font Note </MvCOMMENT>
          <MvASSIGN NAME="l.font" VALUE="Nimbus Mono L:regular" />
          <MvASSIGN NAME="l.font" VALUE="times:bold:italic" />
          <MvASSIGN NAME="l.font" VALUE="Commercial Script.ttf" />
          
          
          <MvASSIGN NAME="l.ptsize" VALUE="12" />
          
          
          <MvASSIGN NAME="l.angle" VALUE="0" />
          <MvASSIGN NAME="l.x" VALUE="10" />
          <MvASSIGN NAME="l.y" VALUE="10" />
          
          
          <MvASSIGN NAME="l.text" VALUE="Ray Yates" />
          
          
          
          
          <MvASSIGN NAME="l.err" VALUE="{ gdImageStringFT( l.image, l.brect, l.fg, l.font, l.ptsize, l.angle, l.x, l.y, l.text ) }" />
          <MvASSIGN NAME="l.void" VALUE="{ [g.module_library_utilities].Image_gdSaveToFile_Type( l.image, 'png', '/temp.png', 'script' ) }">
          <MvASSIGN NAME="l.void" VALUE="{ gdImageDestroy( l.image ) }" />
          
          
          <!DOCTYPE html>
          <html>
          <head>
              <title>gdImageStringFT Test</title>
              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>
          <body>
          <MvEVAL EXPR="{ 'l.err = ' $ l.err $ ' <br>' }"><br>
          <img src="/temp.png"><br>
          
          
          </body>
          </html>
          Hello,

          From the looks of your code. It seems your l.fg variable is incorrect. As its declaration is a string of gdImageColorAllocate instead of calling the function. Try


          Code:
           <MvASSIGN NAME = "l.fg" VALUE = "{ gdImageColorAllocate( l.image, 0, 0, 0 ) }" />
          [I]Kyle Hansen

          Comment


            #6
            Re: MivaScript Gd Library: Font Rendering

            Ok. I Fixed that syntax problem but its still not working. I discovered gdLastError() and added it as shown below,

            Code:
            <MvASSIGN NAME="l.err" VALUE="{ gdImageStringFT( l.image, l.brect, l.fg, l.font, l.ptsize, l.angle, l.x, l.y, l.text ) }" />
            <MvIF EXPR="{ l.err }">
                <MvASSIGN NAME = "l.gd_error_message"   VALUE = "{ gdLastError() }">
            </MvIF>
            Now I'm getting the text for the error:

            gdImageStringFT requires a libgd installation that supports fontconfig

            So is something missing from my 5.20 compiler or in the Empresa 5.20 installation?

            Miva Merchant 9.0000
            MivaScript Engine v5.20
            Database API: mysql
            Ray Yates
            "If I have seen further, it is by standing on the shoulders of giants."
            --- Sir Isaac Newton

            Comment


              #7
              Re: MivaScript Gd Library: Font Rendering

              For posterity, the problem was a missing or incorrect library installation on my test server. Miva corrected it and the gdImageStringFT() is now working.

              My thanks to Kyle and Jon.
              Ray Yates
              "If I have seen further, it is by standing on the shoulders of giants."
              --- Sir Isaac Newton

              Comment


                #8
                Re: MivaScript Gd Library: Font Rendering

                Well for a breif moment I thought this was working. It's ignoring the font no mater what font name or path I use. Currently the .mvc is in the same folder as the fonts.

                Anyone have any suggestions?

                Examples:

                Direct Link: http://dev.moonbeambaby.com/tt_fonts...font%20change?

                Image src: <img src="http://dev.moonbeambaby.com/tt_fonts/fontpreview_image.mvc?font=BOYZRGRO.TTF&font_size= 30&text=Why%20doesn%27t%20the%20font%20change?">

                Code:
                <MIVA STANDARDOUTPUTLEVEL="">
                
                
                <MvASSIGN NAME="l.font" VALUE="{ g.font }">
                <MvASSIGN NAME="l.font_size" VALUE="{ encodeentities(g.font_size) }">
                <MvASSIGN NAME="l.angle" VALUE="{ 0 }">
                <MvASSIGN NAME="l.text" VALUE="{ encodeentities(g.text) }">
                
                
                <MvIF EXPR="{ gdImageStringFT(l.NULL, l.brect, 0, l.font, l.font_size, 0.0, 0, 0, l.text) }">
                    <MvEVAL EXPR="{ gdLastError() $ '<br>' }">
                    <MvEXIT>
                </MvIF>
                
                
                <MvASSIGN NAME="l.width" VALUE="{ l.brect[3] - l.brect[7] + 6 }">
                <MvASSIGN NAME="l.height" VALUE="{ l.brect[4] - l.brect[8] + 6 }">
                <MvASSIGN NAME="l.img_ptr" VALUE="{ gdImageCreate( l.width, l.height ) }">
                <MvASSIGN NAME="l.background" VALUE="{ gdImageColorAllocateAlpha( l.img_ptr, 255, 255, 255, 127) }">
                <MvASSIGN NAME="l.color" VALUE="{ gdImageColorAllocate( l.img_ptr, 60, 60, 60 ) }">
                <MvASSIGN NAME="l.x" VALUE="{ 3 - l.brect[7] }">
                <MvASSIGN NAME="l.y" VALUE="{ 3 - l.brect[8] }">
                <MvASSIGN NAME="l.brect" VALUE="">
                
                
                <MvIF EXPR="{ gdImageStringFT(l.img_ptr, l.brect, l.color, l.font, l.font_size, l.angle, l.x, l.y, l.text ) }">
                    <MvEVAL EXPR="{ gdLastError() $ '<br>' }">
                    <MvEXIT>
                </MvIF>
                
                
                <MvASSIGN name="l.ok" VALUE="{ miva_output_header('Content-Type','image/png') }">
                <MvASSIGN name="l.ok" VALUE="{ miva_output_header('Expires','0')}">
                <MvASSIGN name="l.ok" VALUE="{ miva_output_header('Cache-Control','no-cache, must-revalidate') }">
                <MvASSIGN name="l.ok" VALUE="{ miva_output_header('Pragma','no-cache') }">
                <MvASSIGN NAME="l.ok" VALUE="{ gdImagePngOutput( l.img_ptr ) }">
                <MvASSIGN NAME="l.var" VALUE="{ gdImageDestroy( l.img_ptr ) }">
                
                
                <MvEXIT>
                Last edited by RayYates; 02-02-15, 07:35 AM.
                Ray Yates
                "If I have seen further, it is by standing on the shoulders of giants."
                --- Sir Isaac Newton

                Comment


                  #9
                  Re: MivaScript Gd Library: Font Rendering

                  For posterity:

                  Jon B, tells me that the gdImageStringFT() is only able to display fonts installed on the server. This limits its functionaluty and I have reverted to using .php so my client can simply FTP upload fonts to the folder I specify.
                  Ray Yates
                  "If I have seen further, it is by standing on the shoulders of giants."
                  --- Sir Isaac Newton

                  Comment

                  Working...
                  X