If you have support for fontconfig font patterns, calling
$image->useFontConfig(0);
seems to turn it on, although the docs suggest that only
$image->useFontConfig(1);
turns it on. Is this a bug? I would like to test if its available with
+out turning it on.
In the code below (which prints 1 on my computer),
Expected - Error because 'AlgerianD' isn't a font path
Got - Fontconfig has been switched on, so 'AlgerianD' works, and the p
+ath given to stringFT is matched with Arial or whatever it finds (?).
use strict;
use warnings;
use GD;
use File::Slurp;
my $self = {};
$self->{img} = new GD::Image(64, 64);
$self->{colourhash} = {rect => '000fff', line => '000000'};
setdefaultcolours($self);
$self->{img}->filledRectangle(0, 0, 64, 64, $self->{colours}->{rect});
print $self->{img}->useFontConfig(0), "\n";
$self->{img}->stringFT($self->{colours}->{line}, '/home/dan/.fonts/ALG
+ERINN.TTF', 20, 0, 32, 32, chr(68)) or die $@;
$self->{img}->stringFT($self->{colours}->{line}, 'AlgerianD', 20, 0, 5
+, 32, chr(68)) or die $@;
create($self, 'out.png');
sub create {
my ($self, $out) = @_;
write_file($out, {binmode => ':raw'}, $self->{img}->png) or die "Can
+'t open $out\n";
}
sub setdefaultcolours {
my $self = shift;
while (my ($key, $value) = each %{$self->{colourhash}}) {
$self->{colours}->{$key} = setcolour($self, $key, $value);
}
}
sub setcolour {
my ($self, $colour, $value) = @_;
my @a = map { hex $_ } $value =~ /(..)/g;
if (defined $value) {
$self->{colours}->{$colour} = $self->{img}->colorAllocate(@a);
$self->{colourhash}->{$colour} = $value;
}
return $self->{colours}->{$colour}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.