使用GD库裁剪图像 [英] Crop image using GD library
问题描述
我在Perl脚本中使用GD库,该库允许我绘制一个true-type-font文本.因为一开始我不知道确切的尺寸,所以我设置了
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);
然后我画出文字
my $black = $i->colorAllocate(0, 0, 0);
my @b = $i->stringFT($black, './ttf/cour.ttf', 12, 0, 0, 0, "\n$text");
其中@b
包含我的作物数据.
where @b
contains my crop data.
我希望执行类似这样的操作(语法不正确):
I wish to execute something like this (incorrect syntax):
$i->crop(0, 0, $b[2], $b[3]);
...但是没有这样的crop
功能.
...but there is no such crop
function available.
如何裁剪图像?有一些已知的解决方法吗?
How can I crop my image? Is there some known work-around?
推荐答案
通常,您会使用复制GD
的方法将选定的数据从一幅图像移到新图像中.
Typically you would use the "copy" methods of GD
to move selected data from one image into a new image.
或者,如果您真正需要的只是计算使用GD
绘制的字符串的宽度和高度,请查看
Or if what you really need is just to compute the width and height of a strings drawn with GD
, check out GD::Text
.
这篇关于使用GD库裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!