in reply to Creating an image with GD.

  1. Your code doesn't really compile... looks like it's mainly just from not posting the full script -- but you're also using "white" when you should be allocating a color.
  2. Try using GD::Text::Align or GD::Text::Wrap instead of instantiating the superclass directly (i don't think the superclass can render itself)
  3. When you add things to a GD::Image, you need to do it "bottom up" ... if you're not carefull, your black box will apear on top of your text (so you can't see it)

Try this...

#!/usr/bin/perl -w use strict; use GD; use GD::Text::Align; my $image = new GD::Image( 320, 160 ); my $black = $image->colorAllocate( 0, 0, 0 ); my $white = $image->colorAllocate( 255, 255, 255 ); my $text = new GD::Text::Align( $image, font => gdLargeFont, text => "Perl Coder", color => $white, valign => "top", halign => "center", ); # the order of these two lines is important $image->filledRectangle( 15, 15, 150, 150, $black ); $text->draw( 160 , 80 ); open( IMAGE, ">pc1.png") || die "Couldn't open file: $!\n"; binmode( IMAGE ); print IMAGE $image->png(); close IMAGE;