[英]How can I draw multiple overlay rectangles on an image using ImageMagick
I use the following code to draw an overlay box over another image我使用以下代码在另一个图像上绘制一个覆盖框
convert \
-background '#0002' \
-gravity Center \
-fill white \
-size ${page_width}x30 \
caption:"" \
"${img}" \
+swap \
-geometry +0+100 \
-composite \
"${img}"
however, I want to draw it on multiple positions, for example every other 100 pixels from top to the bottom of the image.但是,我想在多个位置绘制它,例如从图像的顶部到底部每隔 100 个像素。 I can use a loop for this purpose, but I would like to know if there is a better command or solution for this problem?
我可以为此目的使用循环,但我想知道是否有更好的命令或解决方案来解决这个问题?
You can do that by tiling your pattern over the image using Imagemagick.您可以通过使用 Imagemagick 将您的图案平铺在图像上来做到这一点。
Input:输入:
# 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
Result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.