Front page | perl.beginners |
Postings from September 2009
SOLVED re: GD::Text::Wrap
Thread Previous
From:
Jo for lists and groups
Date:
September 29, 2009 09:31
Subject:
SOLVED re: GD::Text::Wrap
Message ID:
C74EE26956BC4A15A77B1CC7FDCBDC7C@Tribble
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;
Thread Previous
-
GD::Text::Wrap
by Jo for lists and groups
-
SOLVED re: GD::Text::Wrap
by Jo for lists and groups