Imagemagick 弧

问题描述

嗨,我在使用 Imagemagick 创建的内容时遇到了问题。

脚本如下:

convert 
-size 300x300 xc:skyblue 
-background none 
-fill #AF280E 
-stroke none 
-draw "circle 150,150 75,250" 
-fill white 
-stroke none 
-draw "circle 150,240" 
-fill #D3DADF 
-stroke none 
-draw 'path "M 260 150 A 1 1,1,41 150"' 
-fill #AF280E 
-stroke none 
-draw 'path "M 260 150 A 1 1,41 150"' 
-fill white 
-stroke none 
-draw "rectangle 290,140 10,170" 
-fill white 
-stroke #AF280E 
-strokewidth 5 
-draw "line 10,137 290,137" 
-strokewidth 40 
-fill white 
-stroke #D3DADF 
-strokewidth 5 
-draw "line 10,170 290,170" 
-strokewidth 40 
-fill white 
-stroke none 
-annotate 100,50 
-draw "circle 150,150" 
-background none
-font Bookman-Light 
-pointsize 12 
-fill navy label"arc text here"  
-distort Arc 340 
logo_2_b6.gif

我想将弧形文字在这些圆圈上,但它一直在闪烁,而且似乎在弧形处也创建了形状。

解决方法

您在使用 ImageMagick 命令的命令行中有几个错误。

让我们把它写得更具可读性,并在每一步之后添加临时文件的写入。这是您的代码的 Unix 语法:

convert -size 300x300 xc:skyblue +write t1.png \
-background none -fill #AF280E -stroke none -draw "circle 150,150 75,250" +write t2.png \
-fill white -stroke none -draw "circle 150,240" +write t3.png \
-fill #D3DADF -stroke none -draw 'path "M 260 150 A 1 1,1,41 150"' +write t4.png \
-fill #AF280E -stroke none -draw 'path "M 260 150 A 1 1,41 150"' +write t5.png \
-fill white -stroke none -draw "rectangle 290,140 10,170" +write t6.png \
-fill white -stroke #AF280E -strokewidth 5 -draw "line 10,137 290,137" +write t7.png \
-strokewidth 40 -fill white -stroke #D3DADF -strokewidth 5 -draw "line 10,170 290,170" +write t8.png \
-strokewidth 40 -fill white -stroke none -annotate 100,50 +write t9.png \
-draw "circle 150,150" +write t10.png \
-background none -font Bookman-Light -pointsize 12 -fill navy label:"arc text here" +write t11.png \
-distort Arc 340 logo_2_b6.gif

这里我已经修复了您的代码:

convert -size 300x300 xc:skyblue +write t1.png \
-background none -fill "#AF280E" -stroke none -draw "circle 150,240" +write t3.png \
-fill "#D3DADF" -stroke none -draw 'path "M 260 150 A 1 1,41 150"' +write t4.png \
-fill "#AF280E" -stroke none -draw 'path "M 260 150 A 1 1,170" +write t6.png \
-fill white -stroke "#AF280E" -strokewidth 5 -draw "line 10,137" +write t7.png \
-strokewidth 40 -fill white -stroke "#D3DADF" -strokewidth 5 -draw "line 10,170" +write t8.png \
-strokewidth 40 -fill white -stroke none -annotate +100+50 " " +write t9.png \
-draw "circle 150,150" +write t10.png \
-background none -font Arial -pointsize 12 -fill navy label:"arc text here" -compose over -composite +write t11.png \
-distort Arc 340 logo_2_b6.gif

首先,您以 +write t9.png 结尾的行对我来说毫无意义。 -annotate 语法是 -annotate +X+Y “一些文本”。 +X+Y 的语法错误(你有 X,Y)。其次,你没有文字。你想做什么?请参阅我以 t9.png 结尾的等效行。我已经更正了您的语法并添加了一些空文本,因为我不知道您在这里要做什么。

第二个失败的是你的标签。它必须是标签:“一些文本”。你离开了冒号 (:)。

第三,该行使您拥有两个版本的 t11.png,即 t11-0.png 和 t11-1.png。标签创建一个新图像。它不会写在之前的图像上。所以你需要添加 -compose over -composite 让它显示在单个 t11.png

它还有助于查看创建的每个图像,看看它是否为该步骤生成了正确的结果。 所以我从我的命令中得到的是:

enter image description here

,

正如 fmw42 所提到的,您的命令存在几个问题。考虑一些改进...

填充颜色、描边颜色和描边宽度等单一设置将适用于所有后续操作,直到您需要更改它们。您不必这样做,但它可以帮助您减少代码的混乱。

制作您的标签在圆括号内做弧形扭曲,以避免扭曲您之前在命令中创建的徽标的其余部分。在制作弯曲文本时,在“-扭曲弧”操作中指定外部半径和内部半径也很有帮助。

您的输出是 GIF,因此您需要在写入输出之前将文本“复合”到徽标图形上,否则 IM 将制作动画 GIF 并且您的文本会闪烁。

这是一个在 bash shell 中运行的 IMv6.8.9 上对我有用的命令。它可能会帮助您朝着好的方向前进...

convert -size 300x300 xc:skyblue +size -background none \
   -stroke none \
   -fill "#AF280E" -draw "circle 150,250" \
   -fill white -draw "circle 150,240" \
   -fill "#D3DADF" -draw 'path "M 260 150 A 1 1,41 150"' \
   -fill "#AF280E" -draw 'path "M 260 150 A 1 1,41 150"' \
   -fill white -draw "rectangle 290,170" \
   -strokewidth 5 \
   -fill white \
   -stroke "#AF280E" -draw "line 10,137" \
   -stroke "#D3DADF" -draw "line 10,170" \
   -strokewidth 40 \
   -stroke none -draw "circle 150,150" \
   +strokewidth \
   \( -font Bookman-Light -pointsize 36 -fill navy -virtual-pixel none \
        label:"arc text here" -distort Arc "340 0 68" \) \
   +repage -gravity center -composite logo_2_b6.gif

enter image description here

编辑添加:

我添加了另一个“标签:”并调整了半径以制作第二段文本并使其与第一段兼容。必须在弧形扭曲之前旋转它才能使字体正确的一面朝上。

convert -size 300x300 xc:skyblue +size -background none \
   -stroke none \
   -fill "#AF280E" -draw "circle 150,150" \
   +strokewidth \
   -gravity center \
   \( -font Bookman-Light -pointsize 48 \
        -fill "#D3DADF" -virtual-pixel none \
        label:"\              upper arc             " \
        -distort Arc "360 0 115" \) \
   -gravity center \
   +repage -composite \
   \( -font Bookman-Light -pointsize 48 \
        -fill navy -virtual-pixel none \
        label:"\              lower arc             " \
        -rotate 180 -distort Arc "360 180 115" \) \
   +repage -composite logo_2_b8.gif

enter image description here

在 ImageMagick 中处理弯曲文本区域可能极具挑战性。请注意,我必须添加空格并进行旋转以确保两个文本标签的大小和中心位置相互匹配。不同的字体、不同数量的文本,甚至在不同的机器上使用相同的字体名称都会影响文本的准确位置。

研究“Circular and Radial Distortion”操作可能有助于创建和对齐圆形图像。