簡體   English   中英

如何使用 ImageMagick 在圖像上繪制多個覆蓋矩形

[英]How can I draw multiple overlay rectangles on an image using ImageMagick

我使用以下代碼在另一個圖像上繪制一個覆蓋框

        convert                 \
         -background '#0002'    \
         -gravity Center        \
         -fill white            \
         -size ${page_width}x30     \
          caption:""      \
          "${img}"              \
         +swap                  \
         -geometry +0+100            \
         -composite             \
          "${img}"  

但是,我想在多個位置繪制它,例如從圖像的頂部到底部每隔 100 個像素。 我可以為此目的使用循環,但我想知道是否有更好的命令或解決方案來解決這個問題?

您可以通過使用 Imagemagick 將您的圖案平鋪在圖像上來做到這一點。

  • 使用 -size... xc:"#0002" 創建一個“#0002”圖像
  • 以類似的方式創建間距高度的完全透明圖像
  • Append 兩個圖像垂直
  • 將它們平鋪在輸入圖像的大小上
  • 在輸入圖像上合成

輸入:

在此處輸入圖像描述

# 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


結果:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM