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

Im writing a simple web application that will allow for using a already made web design and their own name as the banner, to do this ive decided to use GD to simply draw the banner, all it needs to be is a white rectanle with some blue writing in, as far as i could tell this would be easy. I wrote this code to address the problem.
#!/usr/bin/perl -w use GD; use strict; my $im = new GD::Image(569,45) or die "new: $!"; my ($white,$blue) = ( $im->colorAllocate(255, 255, 255), $im->colorAllocate(114, 126, 170) ) or die "colors"; $im->stringFT($blue, "/home/development/archivesystem/ARLRDBD.TTF", 12 +.0, 0.0, 0, 0, "kokomo") or die "writing: $!"; binmode STDOUT or die "binmode: $1"; print $im->png or die "no png :o";
But when i run this code it returns no errors and only prints a white rectangle with no writing, which is quite odd in my opinoin. If any clever people could enlighten me to this situation i would be most appricative. Thanks

Replies are listed 'Best First'.
Re: GD and creating a Banner
by BrowserUk (Patriarch) on Aug 29, 2006 at 02:53 UTC

    The problem is that the x,y you supply is for the bottom left corner of the text. By supplying the origin, you are drawing the text above the top line of your image. Substitute the following and you'll see the text.

    $im->stringFT( $blue, "/home/development/archivesystem/ARLRDBD.TTF", 12.0, 0.0, 0, 45, "kokomo" ) or die "writing: $!";

    Also, the reason you get a white image is because for palette-based images (non-truecolor. Ie. The default), the first color allocated is automatically used as the background color.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: GD and creating a Banner
by GrandFather (Saint) on Aug 29, 2006 at 02:29 UTC

    Irrelevant I'm sure, but $white isn't used.

    Are you sure the font exists in the file as named? In particular, is the case of the file name correct?

    Have you tried placing the text somewhere other than at the origin?

    Does GD understand the font format?


    DWIM is Perl's answer to Gödel
      $white isn't used because i was going to use it later, the font is definatly there and the font type is regconised (the stringFT is espically for TTF fonts) Although i haven't tried starting at the origin. Er, well i have now :) and it doesn't work. Thanks for the input but nah, it doesn't work.
        I take that back, it seems that if i create it at least 10 pixels away from the origin it works, Thanks :D Insight It turns out that it draws from the bottom left of the string so putting it at 0,0 made it invisible :)