Apply overlay image but retain shadows

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
johanndm
Posts: 7
Joined: 2017-12-03T06:58:02-07:00
Authentication code: 1152
Location: Czech Republic

Apply overlay image but retain shadows

Post by johanndm » 2018-03-27T02:07:39-07:00

Hi,

Is there a way to apply an overlay image on base image and retain the shadows?

As example I would like to overlay a fabric onto a image with shadows as in the attached image.

I have tried to make the overlay transparent, but then the colour is not correct, as the base image colour then darkens the final image :-(

Any pointers or ideas will be appreciated.

Thanks
Johann

https://dev.zaxo.cz/362.png (base)
https://dev.zaxo.cz/kiwi.jpg (overlay)

User avatar
fmw42
Posts: 23618
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply overlay image but retain shadows

Post by fmw42 » 2018-03-27T10:27:48-07:00

try

Code: Select all

convert \( kiwi.jpg -crop 430x660+0+0 +repage \)  \
\( 362.png -alpha off -colorspace gray \)  \
-compose hardlight -composite \
\( 362.png -alpha extract \) \
-alpha off -compose copy_opacity -composite \
result1.png
or

Code: Select all

convert \( kiwi.jpg -resize 430x660! \)  \
\( 362.png -alpha off -colorspace gray \)  \
-compose hardlight -composite \
\( 362.png -alpha extract \) \
-alpha off -compose copy_opacity -composite \
result2.png

johanndm
Posts: 7
Joined: 2017-12-03T06:58:02-07:00
Authentication code: 1152
Location: Czech Republic

Re: Apply overlay image but retain shadows

Post by johanndm » 2018-03-28T05:29:19-07:00

Wow thanks - the second option works quite well - i.e. with the resize vs the crop. Thank you very much for the assistance and suggestions!!

johanndm
Posts: 7
Joined: 2017-12-03T06:58:02-07:00
Authentication code: 1152
Location: Czech Republic

Re: Apply overlay image but retain shadows

Post by johanndm » 2018-04-25T12:13:15-07:00

Hmm, Now I'm stuck. The above worked fine for most of the colours but now it seems to change the colour completely on lots of the samples I'm trying?

So for 362.png and kiwi.jpg it works fine, as well for coral-body.png and coral.jpg it works. But for pink-body.png and pink.jpg I get a very dark result?

I played around with the options - like changed colorspace to RGB but them my result is bright red?

Any pointers will be great :-)

Works:
convert \( coral.jpg -resize 430x660! \) \( coral-body.png -alpha off -colorspace gray \) -compose hardlight -composite \( coral-body.png -alpha extract \) -compose copy_opacity -composite new-coral.png
Image
Image
Image

Doesn't work:
convert \( pink.jpg -resize 430x660! \) \( pink-body.png -alpha off -colorspace gray \) -compose hardlight -composite \( pink-body.png -alpha extract \) -compose copy_opacity -composite new-pink.png
Image
Image
Image

User avatar
fmw42
Posts: 23618
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply overlay image but retain shadows

Post by fmw42 » 2018-04-25T12:56:10-07:00

Try this using -compose colorize: (unix syntax)

Code: Select all

convert pink-body.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
pink.jpg -alpha off -compose colorize -composite \
mpr:alpha -compose copy_opacity -composite result.png
Please always provide your IM version and platform, since syntax may vary.

johanndm
Posts: 7
Joined: 2017-12-03T06:58:02-07:00
Authentication code: 1152
Location: Czech Republic

Re: Apply overlay image but retain shadows

Post by johanndm » 2018-04-26T01:20:07-07:00

Hello,

Thanks once again for the advise - always amazed with all the options and power of ImageMagick.

I will have to play a little with the input image pink.jpg to make it slightly lighter so that the final image comes out the correct colour. Perhaps not a "clean" solution but I'm sure it will work as well.

Thanks
Johann

Post Reply