1

I am using GD library in my Perl script that allows me to draw a true-type-font text. Because I don't know exact size at the beginning, I set

my $i = new GD::Image(3000, 3000);

and then I draw my text

my $black = $i->colorAllocate(0, 0, 0);
my @b = $i->stringFT($black, './ttf/cour.ttf', 12, 0, 0, 0, "\n$text");

where @b contains my crop data.

I wish to execute something like this (incorrect syntax):

$i->crop(0, 0, $b[2], $b[3]);

...but there is no such crop function available.

How can I crop my image? Is there some known work-around?

Ωmega
  • 42,614
  • 34
  • 134
  • 203

1 Answers1

1

Typically you would use the "copy" methods of GD to move selected data from one image into a new image.

Or if what you really need is just to compute the width and height of a strings drawn with GD, check out GD::Text.

mob
  • 117,087
  • 18
  • 149
  • 283
  • Yeah, that is simple solution I can see as well. I am looking for some 'smart' solution that would not waste resources... – Ωmega Jul 31 '13 at 18:38