I think I had black text on a black bg or it was outside of the image. After
some trial & error, I got it to work. Corrected version is below along with
notes to clarify since I found the module notes to be scant.

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,180);           
# width,height of image

 
# first spec'd color is a BG (suggest match page?)
# then other colors to be used
 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);
#
                                                
# color below is text color
  my $wrapbox = GD::Text::Wrap->new($image,
      line_space  => 4,
      color       => $red,
      text        => $text
  );
  $wrapbox->set_font(gdGiantFont);

# $wrapbox->set_font('arial',12);               
# Can't spec fonts on our system 

  $wrapbox->set(align => 'left', width => 500); 
# text alignment and paragraph width;

# height will autoscale with text

  $wrapbox->draw(25,10);                        
# left and top positioning of paragraph

  $image->rectangle($wrapbox->get_bounds(25,10),$white);  
# optional colored border around text, use same top and left

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/


  • GD::Text::Wrap Jo for lists and groups
    • SOLVED re: GD::Text::Wrap Jo for lists and groups

Reply via email to