向ImageMagick添加文本时标题,绘制,注释,标签之间的区别 [英] Difference between caption, draw, annotate, label while adding text to ImageMagick

查看:366
本文介绍了向ImageMagick添加文本时标题,绘制,注释,标签之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ImageMagick将文本添加到图像中.我看到了多个使用draw,label,caption,annotate等的示例. 两者之间有什么区别? 我可以使用CLI测试上述命令的结果,但是在尝试使用IM4java由java运行时遇到了麻烦. 有关Java代码段的任何帮助将非常有用.

I'm trying to add text to an image using ImageMagick. I see multiple examples using draw, label, caption, annotate et al. What is the difference between the above? I am able to test the results of the above commands with CLI, however am facing trouble when trying to run by java using IM4java. Any help with java code snippets will be useful.

推荐答案

这就是我的看法-这是很自以为是的,我们欢迎其他人来编辑和添加他们的见识.

Here is how I perceive it - it is quite opinionated and others are welcome to edit and add their insights.

label:像其他包含冒号(:)的运算符一样,例如gradient:xc:logo:label:运算符会生成自己的画布.这意味着您不必在现有图像上绘制/键入文本,而只需在文本上绘制/键入文本,它就会为该文本创建背景.

label: Like other operators that contain a colon (:), e.g. gradient:, xc:, logo:, the label: operator generates its own canvas. That means you don't draw/type text onto an existing image, but rather you just draw/type your text and it creates a background for that text to sit on.

如果事先指定-size,它将创建一个大小合适的画布,并将文本放在适合的最大磅数上.因此,让我们尝试一个固定的宽尺寸:

If you specify -size beforehand, it will create a canvas that size and put the text on it at the biggest pointsize that fits. So, let's try a wide, fixed size:

convert -background black -fill white -gravity center -size 800x100 label:'Stack Overflow' text.png

还有一个狭窄的固定尺寸:

And also a narrow, fixed size:

convert -background black -fill white -gravity center -size 100x100 label:'Stack Overflow' text.png

如果您事先未指定-size,它将以您要求的磅值创建文本并将其放在适当大小的画布上.因此,让我们尝试一个没有画布大小的小磅值:

If you don't specify -size beforehand, it will create the text at the point-size you ask for and put it on a suitably sized canvas. So, let's try a small pointsize without a canvas size:

convert -background black -fill white -gravity center -pointsize 16 label:'Stack Overflow' text.png

还有一个没有画布大小的大磅字号:

And also a large point-size without a canvas size:

convert -background black -fill white -gravity center -pointsize 64 label:'Stack Overflow' text.png

您也可以只指定宽度,而不指定高度,例如使用-size 200x或仅高度而不是宽度,例如-size x50,它将使用最大字体,但只能限制在您指定的尺寸上.

You can also specify just the width but no height, e.g. with -size 200x, or just the height but not the width, e.g. -size x50, and it will use the largest font it can but be constrained in the dimension you specify.

以下内容应使您了解可以影响文本的哪些属性:

The following should give you an idea of which attributes of the text you can affect:

convert -background black -fill yellow -strokewidth 2 -stroke magenta \
    -undercolor blue -size 400x100 -gravity center -font 'AppleChancery' label:'Stack Overflow' text.png

caption:类似于label:,但它也进行自动换行,因此可以将长句子跨多行散布给您.

caption: is like label: but it also does word wrapping so it will spread a long sentence across multiple lines for you all on its own.

pango:是一种类似于HTML的相当复杂的标记语言,它使您可以在句子中间更改字体,颜色,粗体,斜体,下标,上标和其他文本功能.

pango: is a reasonably sophisticated markup language resembling HTML, that allows you to change fonts, colours, bold, italic, subscripts, superscripts and other text features mid-sentence.

-draw "text 10,10 'Your message'"在某种程度上已被弃用,但是它允许您在特定位置绘制现有图像,例如上面显示的10,10.请注意,它没有冒号(:),因此您需要已经有图像/画布才能插入.

-draw "text 10,10 'Your message'" is somewhat deprecated but it allows you to draw onto an existing image at a specific location, such as the 10,10 shown above. Note that it has no colon (:) so you need to already have an image/canvas for it to draw into.

-annotate确实取代了-draw.与-draw一样,您需要已经可以在其上进行绘制的画布/图像,但是与-draw相比,它允许您更轻松地定位,剪切和旋转文本.

-annotate really supersedes -draw. Like -draw, you need to have a canvas/image already on which to draw, but then it allows you to position, shear and rotate your text more readily than with -draw.

安东尼·蒂森(Anthony Thyssen)对所有这些事情进行了精彩的讨论,并在此处

Anthony Thyssen provides an excellent discussion of all of these things, and more here.

这篇关于向ImageMagick添加文本时标题,绘制,注释,标签之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆