Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Converting X11 fonts for GD

by zentara (Archbishop)
on Aug 23, 2012 at 15:27 UTC ( #989336=note: print w/ replies, xml ) Need Help??


in reply to Converting X11 fonts for GD

Another gotcha with GD fonts, is that it is easier to just copy the desired font to your working directory, to get the path right. Here is a simple example. Your GD must be compiled with FreeType IIRC, to enable ttf font support. But then, you can import any ttf font you like.

#!/usr/bin/perl use GD; use strict; use warnings; my ($w, $h) = (200, 200); 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); # Generic.ttf is in script's working directory $img->stringFT($black,"./Generic.ttf",72,0,100,100,'A'); open (IMG, ">$0.png"); print IMG $img->png; close IMG;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh


Comment on Re: Converting X11 fonts for GD
Download Code
Re^2: Converting X11 fonts for GD
by BrowserUk (Pope) on Aug 23, 2012 at 15:42 UTC

    If the black cat hides in a coal cellar, is he really there?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Sure it's there, you just need better infrared vision. :-)

      If you are referring to it being black text on a black background, it works on linux, black text on default white background. I don't know how Windows might color it.


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh

        I didn't read the code closely enough :)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989336]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-09-24 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (244 votes), past polls