Hi, I'm on linux, but your line
my $monaco = GD::Font->load('/System/Library/Fonts/Monaco.dfont') or die "Can't load monaco!";
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.

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;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Using fonts in GD on OS X. by zentara
in thread Using fonts in GD on OS X. by jimt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.