ImageMagick fill color with pattern

93 Views Asked by At

I want to replace specific colours with some patterns using ImageMagick.

I have a simplified example of what I would like to do. Here I would like to replace the red colour with the pattern pattern:right30.

Here the image input is called test.png.

So far, I got

magick test.png -fuzz 40%  -tile pattern:right30 -opaque red room1.jpg

enter image description here

The issue is that my code gives me a black bar instead of the pattern.

enter image description here

The output I am looking for

enter image description here

1

There are 1 best solutions below

5
fmw42 On BEST ANSWER

You can do that in Imagemagick by creating a tiling image of your pattern and a mask image and compositing over the input.

Input:

enter image description here

convert bar_graph.png \
\( -clone 0 -tile pattern:right30  -draw "color 0,0 reset" \) \
\( -clone 0 -fuzz 40% -fill black +opaque red -fill white -opaque red \) \
-compose over -composite bar_graph_tiled.png

enter image description here