We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I got on the bandwagon and put together a snippet to convert text to a translucent .png image. Has lots of options:


    // &width - width of text image in pixels, default 100px
    // &height - height of text image in pixels, default 100px
    // &font - name of font
    // &size - size of font, default 20
    // &color - color of text, comma-separated RGB values (0,0,0 to 255,255,255) default 0,0,0
    // &trans - color of transparency, comma-separated RGB values (0,0,0 to 255,255,255) default 255,255,255
    // $angle - slant of text from ltr, default 0
    // $left - pixels from left edge of image, default 0
    // $top - pixels from top of image to baseline, default $size

    The snippet generates a set of <object> tags rather than <img> tags. Dunno why, except that I just got finished reading the W3C specs on it. So just put the snippet tags where you would normally put <img> tags.

    It expects the .ttf font file to be in the assets/files/fonts folder.

    Thanks to Adrianus Warmenhoven for the gtext snippet’s file saving function, and to a bunch of posters to the php documentation comments.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 22592
      • 11 Posts
      Cool!
        ---
        "Change the rules, challenge the future!"
        • 6726
        • 7,075 Posts
        That’s pretty nice Susan, it seems a bit similar to SiFR, does it not ?

        Anyway, I very much like all those parameter, pretty granular control over the result... that’s cool ! I’ll try this as soon as I get a little time....
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l&#39;outil id
          • 25663 MODX Staff
          • 12,272 Posts
          sIFR requires the use of Flash/JS and can "flash" unreplaced content on a page. This creates an image headline. smiley
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I just looked at sIFR, and it uses Javascript to replace text with a .swf flash image. You have to have Adobe Flash ($699) to make the .swf flash image, then store it in the filesystem. This snippet actually generates the image on-the-fly, or uses an existing image if you’ve already created it.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 25663 MODX Staff
              • 12,272 Posts
              Does this cache already generated files I’d assume?
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Yes. That’s where the "existing image if you’ve already created it" comes from; sorry if I worded that badly.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 4594
                  • 74 Posts
                  Hello to all,

                  i have some strange problems with this snippet. it works half wink :

                  - the image is created, but i can’t specify the position of the text (left, top)

                  here is an image:



                  my settings of the snippet are:

                  $width = isset($width)?$width:425;
                  $height = isset($height)?$height:50;
                  $font = isset($font)?$font:"gara.ttf";
                  $text = isset($text)?$text:"Testing";
                  $trans = isset($trans)?$trans:"255,255,255";
                  $color = isset($color)?$color:"88,89,91";
                  $size = isset($size)?$size:27;
                  $angle = isset($angle)?$angle:0;
                  $left = isset($left)?$left:0;
                  $top = isset($top)?$top:$size;

                  if i change the value of the params "$left", nothing happens...

                  maybe somebody can help?

                  thanks!!
                    • 32942
                    • 141 Posts
                    Hey that’s cool.
                    But I’m just in with sIFR...and sWFIR

                    advantages
                    - accessible (I hop so)
                    - no flash requiered
                    - no flash studio requiered
                    disadvantages
                    - not any font (or am I wrong)
                    - server heavy
                      • 4594
                      • 74 Posts
                      Puh, solved!!

                      the parameters, $left, $top took no influence, because they were not integrated in the function call "ImageTTFText".

                      so this works:

                      // add your white text
                      ImageTTFText ($txt_img, $size, 0, $left, $top, $textcolor, $font, $text);


                      greetz, captain