Hi, I'm not sure what you are trying to do exactly, but the GDTextUtil module seems to do waht you are asking.
#!/usr/bin/perl -w use strict; use GD; use GD::Text::Wrap; my $outfile = shift || "GDWrap.png"; my $gd = GD::Image->new(400,240); my $white = $gd->colorAllocate(255,255,255); my $black = $gd->colorAllocate( 0, 0, 0); my $blue = $gd->colorAllocate(127,127,255); my $red = $gd->colorAllocate(127, 0, 0); #print "No colours: $black ", $gd->colorsTotal, "\n"; my $text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, + sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.'; my $wp = GD::Text::Wrap->new($gd, width => 180, line_space => 4, color => $black, text => $text, ); $wp->set(align => 'left'); $gd->rectangle($wp->get_bounds(10,10), $blue); $wp->draw(10,10); $wp->set(para_space => 5, preserve_nl => 1); $wp->set_font('cetus', 10); $wp->set(align => 'justified', line_space => 0); $gd->rectangle($wp->get_bounds(210,10), $blue); $wp->draw(210,10); $wp->set(para_space => 10, preserve_nl => 0); $wp->font_path('/usr/share/fonts/ttfonts'); $wp->set_font(['Arialn', 'cetus'], 10); $wp->set(align => 'right'); $gd->rectangle($wp->get_bounds(10,120), $blue); $wp->draw(10,120); $text =~ tr/\n//d; $wp->set(text => $text); $wp->set(colour => $white, align => 'center', line_space => 2); $wp->set_font(gdMediumBoldFont, 12); $gd->filledRectangle($wp->get_bounds(210,120), $red); $wp->draw(210,120); print "Writing $outfile\n"; open(GD, ">$outfile") or die "Cannot open '$outfile' for write: $!"; binmode GD ; print GD $gd->png(); close GD;

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

In reply to Re: Automagic text-to-image border calculations by zentara
in thread Automagic text-to-image border calculations by hacker

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.