如何使用ImageMagick在图像上绘制多个覆盖矩形

时间:2020-04-21 16:52:59

标签: imagemagick draw

我使用以下代码在另一张图片上绘制一个叠加框

plt.figure(figsize=(10, 4))
plot_clustered_stacked([df_1, df_2],["df_1", "df_2"])
plt.show()

plt.clf()
plt.close()

但是,我想在多个位置上绘制它,例如从图像的顶部到底部每隔100个像素绘制一次。 我可以为此使用循环,但是我想知道是否有更好的命令或解决方案?

1 个答案:

答案 0 :(得分:1)

您可以通过使用Imagemagick在图像上平铺图案来实现。

  • 使用-size ... xc创建一个“#0002”图像:“#0002”
  • 以类似的方式创建间距高度的完全透明的图像
  • 垂直添加两个图像
  • 将其平铺到输入图像的整个尺寸上
  • 在输入图像上进行复合

输入:

enter image description here

# Line 1: read the input
# Line 2: create the tile (spacing set to 50 in transparent section)
# Line 3: tile it out over the size of the input by replacing it on the input
# Line 4: do the composite
# Line 5: save the output

convert lena.png \
\( -size 256x30 xc:"#0002" -size 256x50 xc:none -append -write mpr:tile +delete \) \
\( -clone 0 -tile mpr:tile -draw "color 0,0 reset" \) \
-compose over -composite \
result.png


结果:

enter image description here

相关问题