JimDuyer has asked for the wisdom of the Perl Monks concerning the following question:

Hello again. I have used $im->stringUp with GD and it prints text beginning on the bottom and ending on the top. I am trying to print text in a square. So I use $im->string for the top, $im->stringUp for the left side (adjusting the y axis) and $im->string for the bottom, (adjusting the y axis) and would LIKE to have a $im->stringDOWN equivalent, to print the text vertically from top to bottom, facing the other direction from the other stringUp text. Is this doable in any way ? I need to use the GD module for the rest of the program, and would appreciate suggestions. Thanks.

Replies are listed 'Best First'.
Re: Help with GD text
by BrowserUk (Patriarch) on Jun 17, 2011 at 20:37 UTC
    and would LIKE to have a $im->stringDOWN equivalent,

    There is no such animal for bit-mapped fonts.

    • If you have a build of GD that based on a build of libgd that includes FreeType font support, then you can use stringFT() methods to rotate text to any angle you like.
    • Or, you could draw the string up in a separate (sized) image, use the rotate180() method to get the down written text and then the copy() method to blit it into the target image.

      The problem would be determining the size of draw text. The bit-mapped fonts support doesn't seem to have any mechanism for determining the bounds of the drawn text.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks for replying... I made it harder by not stating in advance that I am using my own true type font that is on my server. I don't think I can draw the image and paste it together, as I already have a background image that I am slamming this text image on to. I will be using the string up, could you tell me how to rotate the text to any angle I like ? I need the -90, I suppose, as I need to have the right hand side text go from top to bottom and face to the right. Any ideas ?
        could you tell me how to rotate the text to any angle I like ?

        See the documentation for  $image->stringFT( fgcolor, fontname, ptsize, angle, x, y, string ) ...

        The arguments are as follows: fgcolor Color index to draw the string in fontname A path to the TrueType (.ttf) font file or a font pattern +. ptsize The desired point size (may be fractional) angle The rotation angle, in radians (positive values rotate co +unter clockwise) x,y X and Y coordinates to start drawing the string string The string itself If successful, the method returns an eight-element list giving the bou +ndaries of the rendered string: @bounds[0,1] Lower left corner (x,y) @bounds[2,3] Lower right corner (x,y) @bounds[4,5] Upper right corner (x,y) @bounds[6,7] Upper left corner (x,y)

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.