Imager - Imager and UNICODE characters

Posted on Wed Oct 18 12:39:46 2006 by llhca
Imager and UNICODE characters

I desire release of a BMP picture with a text who have some UNICODE characters.

For example :

Hello ☺!

(Unicode character: smiley white face,U+263A )

The WINDOWS font using have this character

The bmp released have the UNICODE character replaced with three 'ASCII' characters,

Imager can it create images with characters UNICODE?

Where is the problem(s) in the following code ?

PERL: ActiveState

v5.8.8 built for MSWin32-x86-multi-thread

IMAGER:

v0.54

#!/usr/bin/perl #-w use warnings; use strict; use Imager; use encoding 'utf8'; # use a different file, depending on the font support you have in # your installed Imager. my $Font_Name="Courier New Bold"; my $font = Imager::Font->new(face=>$Font_Name) or die "Cannot load '" . $Font_Name . ": ", Imager->errstr; my $text ="Hello \x{263A}!"; my $text_size = 12; my $bbox = $font->bounding_box(string=>$text, size=>$text_size, ); my $X_Text=$bbox->total_width(); #debug print "long. texte: $X_Text\n"; my $Decal=$X_Text-$bbox->display_width(); #debug print "decal: $Decal \n"; my $Y_Text=$bbox->text_height(); #debug print "Haut. texte: $Y_Text\n"; my $Border_size=2; #debug print "bordure: $Border_size\n"; my $Text_Delim=1; #debug print "Delim: $Text_Delim\n"; my $X_Img_size=($X_Text-$Decal)+(($Border_size+$Text_Delim)*2); my $Y_Img_size=$Y_Text+(($Border_size+$Text_Delim)*2); my $image = Imager->new(xsize=>$X_Img_size, ysize => $Y_Img_size); #debug print "long image \$X_Img_size: $X_Img_size, Width: " . $image->getwidth . "\n"; #debug print "Haut image \$Y_Img_size: $Y_Img_size, height: " . $image->getheight . "\n"; $image->box(xmin => 0, ymin => 0, xmax => ( $X_Img_size-1), ymax => ($Y_Img_size-1), filled => 1, color => 'blue'); $image->box(xmin => $Border_size, ymin => $Border_size, xmax => (($image->getwidth)-$Border_size)-1, ymax => (($image->getheight)-$Border_size)-1, filled => 1, color => 'green'); #debug print " max x zone int: ".(($image->getwidth)-($Border_size))."\n"; #debug print " max y zone int: ".(($image->getheight)-($Border_size))."\n"; $font->align(string => $text, size => $text_size, color => 'red', x => ($image->getwidth/2)+$Decal, y => $image->getheight/2, halign => 'center', valign => 'center', image => $image); #debug print "Texte: \n $text\n"; $image->write(file=>'test1.bmp') or die 'Cannot save test1.bmp: ', $image->errstr;
Direct Responses: 3279 | Write a response