I have an html form which takes only one field - a textarea.
From this, I want to split the field on \n's, and then make
an image containing all the lines, with the breaks on each \n.
Here is the code I have:

#!/usr/local/bin/perl -w # Simple image creation script - hopefully use strict; use GD; use CGI qw(:standard); ######################################################### # Set up all the globals # ######################################################### # create a new image my $im = new GD::Image(400, 200); my $query = new CGI; # allocate some colors my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $red = $im->colorAllocate(255,0,0); my $blue = $im->colorAllocate(0,0,255); # make the background transparent and interlaced $im->transparent($white); $im->interlaced('true'); # Put a black frame around the picture $im->rectangle(0,0,399,199, $black); ########################################################## # End of the globals ########################################################## # MAIN # ########################################################## my $text = $query->param("text"); make_image($text); exit(0); ########################################################## # Make an image from the lines in the array sub make_image { my $text = shift; my $counter = 80; my @lines = split(/\n/,$text); foreach my $line (@lines) { $im->stringTTF($black, "/home/httpd/html/ribbon.ttf", 12, 0, 1 +80, $counter, "$line"); if ($@) { $im->string(gdSmallFont, 50, 150, "$@", $black); die "Cannot print!$!\n"; } $counter += 10; } binmode STDOUT; print $query->header(-type=>'image/png'); print $im->png; }
Unfortunately, the image is only showing " 'I " (The test
text is 'I love my wife'
(It's just a test, after all ;-)

As you can see, each line should be 10 pixels below the previous.
Can anyone help?

What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

In reply to a newbie to GD by tame1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.