tomaszbak
tomaszbak

Reputation: 8287

Transparent PNGs and a JPEG combine in ImageMagick

I have a case where I need to combine two transparent layers on top of JPEG files.

Here a sample setup:

wget -O bg.jpg http://www.grahamowengallery.com/photography/Flowers/roadside-flowers.jpg
wget -O layer.png http://www2.picturepush.com/photo/a/6271450/640/TRANSPARENT-EMBELLISHMENTS/pink-flower-transparent-png.png
wget -O logo.png http://upload.wikimedia.org/wikipedia/commons/0/0d/Imagemagick-logo.png

I can get desired result with commands:

composite bg.jpg \( -compose Overlay layer.png \) bg2.jpg
composite bg2.jpg \( -compose Overlay logo.png \) result.jpg

This is good, but I want to avoid writing bg2.png to drive.

I tried:

composite bg.jpg \( -compose Overlay layer.png \) \( -compose Overlay logo.png \) result2.jpg

but this results on layer.png on black background. How can I fix this?

Upvotes: 2

Views: 6375

Answers (2)

Bonzo
Bonzo

Reputation: 5299

I can not test this at the moment but you may be able to use layers merge and you should be able to use the URLs in your code.

$cmd = "http://www.grahamowengallery.com/photography/Flowers/roadside-flowers.jpg ".
" http://www2.picturepush.com/photo/a/6271450/640/TRANSPARENT-EMBELLISHMENTS/pink-flower-transparent-png.png ".
" http://upload.wikimedia.org/wikipedia/commons/0/0d/Imagemagick-logo.png -layers merge ";
exec(" convert $cmd result.jpg ");

You are not using any positioning for your layers - are you going to introduce that later? If so you can add -page +0+0 in front of each image to locate them where you want. +0+0 would be changed to the location.

Upvotes: 2

moropus
moropus

Reputation: 3782

I couldn't make composite working, but convert works:

convert.exe bg.jpg layer.png -compose Overlay -composite logo.png -compose Overlay -composite result2.jpg

Further reading: http://www.imagemagick.org/Usage/compose/

Upvotes: 4

Related Questions