Page 1 of 1

Apply overlay image to masked areas

Posted: 2019-07-09T22:16:23-07:00
by seeit
Hi

I have an image with say 3 known colours and I want to go through the 3 colours, replace them with another colour and apply an overlay to the colour changed areas. It is being handled by a PHP script, so I can use that to loop if that's easier.

To clarify:

1) replace colour X with colour Y
2) apply texture overlay (multiply/screen) to new colour Y area
3) repeat 1 and 2 as required
4) output combined image

I have tried a lot of different combinations of commands I found here - but I either end up applying the overlay to the entire image or some other incorrect

I'm using ImageMagick 6.7.8-9

Any help would be appreciated.

Re: Apply overlay image to masked areas

Posted: 2019-07-09T23:02:22-07:00
by fmw42
You will have to mask to overlay so that it does not change the other two colors. Perhaps you should post a link to your input image and specify what your platform is.

Re: Apply overlay image to masked areas

Posted: 2019-07-09T23:15:59-07:00
by seeit
I'm using command line through PHP

Attached is an image with 3 colours and an example of a texture to be applied to (there are a few) - one would be applied to each area

Image

Image

Re: Apply overlay image to masked areas

Posted: 2019-07-10T10:00:16-07:00
by fmw42
In Unix syntax:

Code: Select all

convert texture.png -rotate 90 texture2.png

Code: Select all

convert image.png +write mpr:img +delete \
\( mpr:img -fill pink -opaque "rgb(0,191,242)" \) \
\( -clone 0 -fill white -opaque pink -fill black +opaque white \) \
 texture.png +swap \
-compose multiply -composite +write mpr:img +delete \
\( mpr:img -fill skyblue -opaque "rgb(243,109,79)" \) \
\( -clone 0 -fill white -opaque skyblue -fill black +opaque white \) \
 texture2.png +swap \
-compose multiply -composite result.png
Image

For Windows, remove \ from before \( and before \) and replace end of line \ with ^.

Re: Apply overlay image to masked areas

Posted: 2019-07-10T16:31:12-07:00
by seeit
You are an absolute champion - a few of my attempts were close but not quite right. Thanks a lot.