You create a new image:

my $gd = GD::Image->new($img_width, $img_height);

Write some text into it:

my $wrapbox = GD::Text::Wrap->new($gd, line_space => 3, color => $colors{$opt{'c'}}, text => $opt{'t'}, );

Then load an image from disk:

$source_img = GD::Image->newFromJpeg($opt{'i'});

And attempt to copy the text onto it:

$gd->copy($source_img, 1, 1, 0, 0, $img_width, $img_height);

Accept that you are copying from the image you loaded, into the image containing the text! Thereby overwriting the text you drew with a 300 x 300 section of the image--assuming it is at least that big. You then write that to disk.

Does that accurately sum up the results you describe as "it doesn't properly "copy""?

The copy operation should almost certainly be more like:

$source_img->copy($gd, 1, 1, 0, 0, $img_width, $img_height);

Though you should probably use the width & height of the bounding box returned from the text operation to limit the amount of the original image you overwrite.

Perhaps better still, depending upon your goals, would be to simply write the text directly onto the loaded image. You could then set the background color of the text operation to transparent and get see-through text.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

In reply to Re: Add text to image by BrowserUk
in thread Add text to image by xachen

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.