causes my script to prematurely exit with "Success" at that line. If I comment out the line, and use one of my fonts, your script works. However, notice in the next snippet, that you may need your gd libs to be compiled with TrueType font support. I don't know what monaco is.my $monaco = GD::Font->load('/System/Library/Fonts/Monaco.dfont') or die "Can't load monaco!";
Works:
#!/usr/bin/perl use GD; use strict; use warnings; my ($w, $h) = (50, 50); my $img = GD::Image->new($w, $h); my $white = $img->colorAllocate(255,255,255); my $black = $img->colorAllocate(0,0,0); # this line causes a premature exit with "success". #my $monaco = GD::Font->load('Generic.ttf');# or die "Can't load monac +o!"; $img->rectangle(10,10,20,20,$black); $img->stringFT($black,"./Generic.ttf",12,0,10,10,'A'); open (IMG, ">$0.png"); print IMG $img->png; close IMG;
Now here is another snippet, that may be useful:
#!/usr/bin/perl use strict; use warnings; use GD; #Andrew Gaffney my $im = new GD::Image(61,20); my ($text, $saveto) = @ARGV || ('Hi There', $0.'.png'); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $gray = $im->colorAllocate(132,132,132); my $blue = $im->colorAllocate(206,206,255); my $leftblue = $im->colorAllocate(231,231,255); my $bottomblue = $im->colorAllocate(165,165,206); my $rightblue = $im->colorAllocate(123,123,156); my $topblue = $im->colorAllocate(214,214,255); $im->transparent($white); $im->interlaced('true'); $im->filledRectangle(0,0,60,19,$white); $im->filledRectangle(3,3,60,19,$gray); $im->filledRectangle(0,0,57,16,$blue); $im->rectangle(0,0,57,16,$white); $im->line(1,0,56,0,$topblue); $im->line(57,1,57,15,$rightblue); $im->line(1,16,56,16,$bottomblue); $im->line(0,1,0,15,$leftblue); # Dry run to determine size of outputted text #this requires libgd was compiled with TrueType Font support my (@bounds) = GD::Image->stringFT($black,"./Generic.ttf",9,0,0,0,$tex +t); # Use above dimensions to center text $im->stringFT($black,"./Generic.ttf",9,0,((57 - $bounds[2])/2),13,$tex +t); #$im->string(gdLargeFont, 2, 2, $text, $black); open IMAGE, "> $saveto" or die "Can't open $saveto\n"; binmode IMAGE; print IMAGE $im->png; close IMAGE;
In reply to Re: Using fonts in GD on OS X.
by zentara
in thread Using fonts in GD on OS X.
by jimt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |