in reply to Add text to image

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"