Crop image using GD library

天大地大妈咪最大 提交于 2019-12-13 02:38:16

问题


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?


回答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.



来源:https://stackoverflow.com/questions/17978193/crop-image-using-gd-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!