I'd like to note something.
I've used GD and ImageMagick with text before, and had some troubles. The fonts I would choose would not show up. Instead, some random looking font would render.

This is because these modules can use to be told exactly what you're talking about- as in font- as in the absolute path to the font file.

Look at GD usage in regards to text..
If you're having trouble getting the font you want- to render- try specifying as argument, instead of font 'name', the font path.

You can search for the font you want via.. for example..
find / -type f -iname "*arial*"

update

Actually... you have to load the font.. as...

my $font = GD::Font->load($font_path) or die('cant load font'); $image->string($font,50,30,$content,$red); exit;

In my script I get an error 'panic: malloc at test.pl line 14.' When I try to load the font..

#!/usr/bin/perl use strict; use Cwd; use Carp; use GD; my $font_arg ='/home/leo/misc/fonts/Suicide.ttf'; #/usr/share/fonts/ttf/unvr57w.ttf'; my $jpeg_quality=90; my $content = `date`; my $out = sprintf "/tmp/%s.jpg", time; -f $font_arg or die; # just in case my $font = GD::Font->load($font_arg) or die('cant load font'); # error + here # create a new image my $image = new GD::Image(700,350); my $red = $image->colorAllocate(255,0,0); $image->string($font,50,30,$content,$red); # not making it to this lin +e open(DATEI ,'>', $out) || die "could not write image: +$!"; binmode DATEI; print DATEI ($image->jpeg($jpeg_quality)); close(DATEI); warn "saved $out\n"; exit;

I checked the file too..

[leo@mescaline ~]$ file /home/leo/misc/fonts/Suicide.ttf /home/leo/misc/fonts/Suicide.ttf: TrueType font data

In reply to Re: GD string size by leocharre
in thread GD string size by Anonymous Monk

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.