develooper Front page | perl.beginners | Postings from September 2009

GD::Text::Wrap

Thread Next
From:
Jo for lists and groups
Date:
September 28, 2009 15:55
Subject:
GD::Text::Wrap
Message ID:
48107CC27FCA44FFB210996169CE8FA1@Tribble
I originally started with GD $image->string(); which worked fine, except the
text is too long. I then found text::wrap could be the solution, but I can't
get it to work. I am trying to print red text on a black background. I am
only getting the background. What am I missing or doing wrong?

Jo 



#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use GD;
use GD::Text::Wrap;

 my $query = new CGI;

#my $text="hello";
 my $text = <<EOSTR;
This is a very long line that is going to exceed the box width so we meed to
try to get it to wrap within the space we have reserved for our image. 
EOSTR

 my $image = new GD::Image(600,100);
 my $black = $image->colorAllocate( 0, 0, 0);
 my $red = $image->colorAllocate( 255, 0, 0);
 my $white= $image->colorAllocate(255,255,255);

# instead try wrapping the text
# $image->string(gdGiantFont,20,10,$text,$red);
#
  my $wrapbox = GD::Text::Wrap->new($image,
      color       => $white,
      text        => $text,
  );
  $wrapbox->set_font(gdGiantFont);
  $wrapbox->set(align => 'left', width => 400);
  $wrapbox->draw(10,140);

  $image->rectangle($wrapbox->get_bounds(10,140), $red);

print $query->header("image/png");
binmode STDOUT;
print $image->png();

exit;


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About