Apply overlay image to masked areas

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
seeit
Posts: 3
Joined: 2019-07-09T21:54:43-07:00
Authentication code: 1152

Apply overlay image to masked areas

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply overlay image to masked areas

Post 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.
seeit
Posts: 3
Joined: 2019-07-09T21:54:43-07:00
Authentication code: 1152

Re: Apply overlay image to masked areas

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply overlay image to masked areas

Post 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 ^.
seeit
Posts: 3
Joined: 2019-07-09T21:54:43-07:00
Authentication code: 1152

Re: Apply overlay image to masked areas

Post by seeit »

You are an absolute champion - a few of my attempts were close but not quite right. Thanks a lot.
Post Reply