Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Font question regarding GD.pm

by Baz (Friar)
on Jul 19, 2005 at 13:40 UTC ( [id://476085]=perlquestion: print w/replies, xml ) Need Help??

Baz has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I wish to include text on a png image. With respect to the following page:

http://baz.perlmonk.org/surname_alba.cgi?name=Griffin,

I'd like to include "Scale: 0 to 9" and "Scale: 0 to 1.21%" within the png images. The problem I've had with this is that the four built-in GD fonts, gdLargeFont, gdSmallFont, gdMediumBoldFont, and gdTinyFont, are much too small for the images I'm using. The Copyright text was included via a seperate bitmap. Is there any way of using other font types with GD::Image::string, besides the four built-in fonts? If not, then I guess my only option is to create 10 bitmaps for the numbers 0 to 9, and use them to produce the numbers I need.

Cheers,
Barry.

Replies are listed 'Best First'.
Re: Font question regarding GD.pm
by socketdave (Curate) on Jul 19, 2005 at 13:51 UTC
    I've never tried this, but it looks like you can specify a path to a font file with GD::Text: $gd_text->set_font('/usr/fonts/arial.ttf', 12);.... That may be worth a try.
      Thanks for the reply.

      OK, lets say I create the following text using GD::Text, how then do I use it with a GD::Image object? In other words, what method do I call to position $gd_text on a png image?
      my $gd_text = GD::Text->new( text => 'Some text', font => 'times.ttf', ptsize => 14, );
        Take a peek at this thread:
        http://groups-beta.google.com/group/comp.lang.perl.misc/browse_thread/thread/e0e3efc840f45279/0ec9568510bfb279?q=gd::text+gd::image&rnum=2&hl=en#0ec9568510bfb279
        The section titled "GD + GD::Text example" may give you a starting point. If this doesn't help, let me know. This is a useful thing to know and I'll try to get it working...
        Found the method $im->stringFT($black,$font,30.0,-0.5,130,130,"Goodbye cruel world!");
        and it works fine.
Re: Font question regarding GD.pm
by BrowserUk (Patriarch) on Jul 19, 2005 at 15:37 UTC

    Try this (having adjusted the path to suit):

    #! perl -slw use strict; use GD; my $img = GD::Image->new( 1000, 120, 1 ); my $index = $img->colorAllocate( 255, 0, 0 ); my @bounds = $img->stringFT( $index, "c:\\windows\\fonts\\Coprgtb.ttf", 72, 0, 100, 100, "Hello world" ); open IMG, '>', "junk.png"; binmode IMG; print IMG $img->png; close IMG;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://476085]
Approved by jbrugger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-03-28 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found