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

Good day monks. I am using method stringFT in GD to generate text inside some graphics. In this text I want to include some up- and down-arrows. I have loaded the Arial font, and it has these charasters in its extended charset. The according to the windoze special char browser, the uparrow is char 2191 hex and the down arrow is 2193 hex.

Trouble is I don't know how to specify a unicode char in stringFT. The docs offer a "charmap" option to method stringFT but the authors says "The interaction between Perl, Unicode and libgd is not clear to me, and you should experiment a bit if you want to use this feature." (Geez, if he doesn't even understand it...)

The docs don't give any charmap examples so I'm not even sure how to experiment. Your advice appreciated!

Steve

Replies are listed 'Best First'.
Re: Using Unicode chars in GD
by davidrw (Prior) on May 22, 2005 at 17:35 UTC
    I don't know about GD, but i just recently did this using Image::Magick, so perhaps either the same technique of the \x codes will work in GD or if it's possible you can use ImageMagick for your solution instead of GD...
    use Image::Magick; my $image = Image::Magick->new(); ... $image->Annotate( x=>$x, y=>$y, text=>"Up: \x{2191} and Down: \x{2193}", font=> '@YOURFONT.TTF', pointsize => 12, stroke => 'black', );
      That did it. Here's the working GD code, in case anyone is insterested. Many thanks......Steve
      use strict; use GD; my $image = GD::Image->new(200,100); my $white = $image->colorAllocate(255,255,255); my $black = $image->colorAllocate(0,0,0); my $uparrow = "\x{2191}"; my $dnarrow = "\x{2193}"; $image->stringFT($black,'/windows/fonts/arial.ttf',12,0,80,50,"up: $up +arrow dn: $dnarrow"); open(OUT,">test.png") or die "Can't open output: $!\n"; binmode OUT; print OUT $image->png; close OUT;
Re: Using Unicode chars in GD
by cosimo (Hermit) on May 23, 2005 at 15:56 UTC
    Can you tell us which version of perl are you using? Just for the record... 5.8.x ?
      Of course, it's perl 5.8.4 and mod GD ver 2.19

      Steve