Page 1 of 1

Apply overlay image but retain shadows

Posted: 2018-03-27T02:07:39-07:00
by johanndm
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)

Re: Apply overlay image but retain shadows

Posted: 2018-03-27T10:27:48-07:00
by fmw42
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

Re: Apply overlay image but retain shadows

Posted: 2018-03-28T05:29:19-07:00
by johanndm
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!!

Re: Apply overlay image but retain shadows

Posted: 2018-04-25T12:13:15-07:00
by johanndm
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

Re: Apply overlay image but retain shadows

Posted: 2018-04-25T12:56:10-07:00
by fmw42
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.

Re: Apply overlay image but retain shadows

Posted: 2018-04-26T01:20:07-07:00
by johanndm
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

Re: Apply overlay image but retain shadows

Posted: 2019-02-12T06:05:11-07:00
by johanndm
Hello Fred,

I'm trying to do something very similar than before, except this time I'm using the same set of white base images and then overlaying a new colour photo for each new fabric - but I just don't seem to get it working :-) What would the optimal "recipe" be to make it work to overlay the colours on this base please.

Base images:
https://dev.zaxo.cz/im/base-1.png
https://dev.zaxo.cz/im/base-2.png

Overlay Photos:
https://dev.zaxo.cz/im/kiwi.jpg
https://dev.zaxo.cz/im/koralova.jpg
https://dev.zaxo.cz/im/seda.jpg
https://dev.zaxo.cz/im/pivonkova.jpg

I will keep experimenting but would be great if you could please give me some pointers please.

Kind regards,
Johann

Re: Apply overlay image but retain shadows

Posted: 2019-02-12T15:02:34-07:00
by fmw42
try -compose multiply rather than -compose hardlight

Code: Select all

dims=`convert base-1.png -format "%wx%h" info:`
convert \( kiwi.jpg -resize $dims! \)  \
\( base-1.png -alpha off -colorspace gray \)  \
-compose multiply -composite \
\( base-1.png -alpha extract \) \
-alpha off -compose copy_opacity -composite \
result1.png

dims=`convert base-2.png -format "%wx%h" info:`
convert \( kiwi.jpg -resize $dims! \)  \
\( base-2.png -alpha off -colorspace gray \)  \
-compose multiply -composite \
\( base-2.png -alpha extract \) \
-alpha off -compose copy_opacity -composite \
result2.png

Re: Apply overlay image but retain shadows

Posted: 2019-02-14T04:26:56-07:00
by johanndm
:D :D :D Excellent - wow tried many other things but not "multiply"

Thanks once again for saving my bacon and helping - great great product and community!!