jimt has asked for the wisdom of the Perl Monks concerning the following question:
I'm stumped. How can I load up an external font and have GD use it? I just want to print out a string into an image, then save it as a png. Nothing fancy. But I haven't been able to track down an example that works.
My gd config summary tells me that I have support for PNG, JPEG, Freetype 2.x, Fontconfig, Xpm, and pthreads. My GD is up to date w/2.35, and my gd version is 2.0.33. I'm running 10.4.8 on a macbook w/a core duo. Sample script along with sample results are attached. What do I need to change to make this work? Did I miss the proper incantation to produce my string, or am I doing it properly with one of the methods down below and something external is thwarting me? Any pointers appreciated.
#!/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); my %pixmap = (); my $monaco = GD::Font->load('/System/Library/Fonts/Monaco.dfont') or die "Can't load monaco!"; $img->rectangle(10,10,20,20,$black); #this gives me a bus error #$img->stringFT($black,'/System/Library/Fonts/Monaco.dfont',12,0,10,10 +,'A'); #this does nothing #$img->stringFT($black,$monaco,12,0,10,10,'A'); #this dies with "font is not of type GD::Font " #$img->string('/System/Library/Fonts/Monaco.dfont',10,10,'A',$black); #this one does nothing #$img->string($monaco,10,10,'A',$black); $img->rectangle(0,0,10,10,$black); open (IMG, ">/Users/jim/Desktop/img.png"); print IMG $img->png; close IMG;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using fonts in GD on OS X.
by zentara (Cardinal) on Oct 23, 2006 at 16:38 UTC | |
Re: Using fonts in GD on OS X.
by Cabrion (Friar) on Oct 24, 2006 at 01:45 UTC | |
Re: Using fonts in GD on OS X.
by jimt (Chaplain) on Oct 24, 2006 at 14:03 UTC |