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;


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to