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

Okay, here's my question:

I'm trying to create an image-based counter (so I don't have to mess with SSI) on a WinNT-based web server. After some bad luck with using Image::Magick to append digit images together (ending up with rendering problems trying to send the image result to STDOUT... but that's an entirely different story).

I then turned to GD.pm to see if that would help -- what really caught my eye was stringTTF().

However, everytime I make a call to this function with a string, I get a string of "null" characters (i.e. those blank box things) drawn onto the image. I've noticed other examples that do the exact same steps I do and come out with favorable results.

Now I know that stringTTF is actually opening the font file without problems, but I'm wondering if there's anything special that I have to do to escape the string in any fashion before feeding it to stringTTF.

The catch is: I'm using ActiveState's GD bundle through their PPM. (And I'm beginning to think that that just may be the problem too, but...) So if anyone's got any suggestions, I'll be glad to try 'em. =)

Replies are listed 'Best First'.
Re: GD::Image-stringTTF() problems....
by Albannach (Monsignor) on May 04, 2001 at 00:25 UTC
    The following test works fine with ActiveState (build 623, their GD ver 1.27.2]. My guess is you are trying to print characters that aren't defined in the font you are specifying, except that doesn't seem likely with simple numbers. Anyway, there is nothing fancy about the string, to answer that part of the question.
    use strict; use warnings; use GD; my $im = new GD::Image(150,60); my $white = $im->colorAllocate(255,255,255); # UPDATE without this th +e background # will be the same as th +e text colour my $blue = $im->colorAllocate(0,0,255); # might as well allocate this + too while I'm at it... my @bounds = $im->stringTTF($blue,'c:/i386/Arial.ttf',22,0,0,36,'123 J +aPh!'); if (!@bounds) {print "TTF error: $@\n";} print join ':', @bounds; open OUT, '>foo.jpg' or die "Couldn't open output: $!"; binmode OUT; print OUT $im->jpeg; close OUT;
    Update: Aargh you're correct! I actually did test this but as part of a larger script which had already set some colours. I've corrected the above code as marked (thanks!). And for the record this was under NT4. I'll have to try it on a Win9x box sometime.

    --
    I'd like to be able to assign to an luser

      ...you only made one call to colorAllocate, though; wouldn't that set the background color to the font color and give you just a blue square? (At least that's what it did for me...)

      Anyways, think I found my problem -- apparently, it's a WinNT/Win9x incompatability thing, because I migrated my code over to the server and it works fine. *sighs*

      Thanks for the help, though. =)