简体   繁体   English

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

[英]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 将您的图案平铺在图像上来做到这一点。

  • Create a "#0002" image using -size... xc:"#0002"使用 -size... xc:"#0002" 创建一个“#0002”图像
  • Create a fully transparent image of the height of your spacing in a similar manner以类似的方式创建间距高度的完全透明图像
  • Append the two images vertically Append 两个图像垂直
  • Tile them out over the size of the input image将它们平铺在输入图像的大小上
  • Composite that over the input image在输入图像上合成

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.

相关问题 如何使用imagemagick在图像上绘制X - how to draw an X on an image with imagemagick 如何使用ImageMagick替换图像中的白色矩形? - How can I replace the white rectangle within an image using ImageMagick? 如何在“绘制矩形”命令中使用imagemagick属性? - How can I use imagemagick attributes in the draw rectangle command? 有没有办法使用 ImageMagick 在图像周围绘制边框? - Is there a way to draw an border around an image using ImageMagick? 用imagemagick画多个圆圈 - draw multiple circles with imagemagick 使用imagemagick如何将图像切割成几个单独的图像? - Using imagemagick how can i slice up an image into several separate images? 如何调整已经使用Magickwand(PHP)/ ImageMagick上传的图像的大小? - How can I resize an image already uploaded using Magickwand(PHP)/ImageMagick? 如何使用PHP中的Imagemagick修剪图像的左侧和右侧? - How can I trim just the left and right side of an image using Imagemagick in PHP? 使用 ImageMagick,我如何调整图像的大小以具有最小的高度或宽度,这是首先达到的 - Using ImageMagick, how can I resize an image to have minimum height or width, which ever is reached first 如何检测图像内一张纸的边界并使用 ImageMagick 裁剪它? - How can I detect borders of a piece of paper inside of an image and crop it using ImageMagick?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM