Copy-opacity to cut out transparent mask -composite problems

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
weatherbadger
Posts: 15
Joined: 2010-03-01T09:52:50-07:00
Authentication code: 8675308
Location: Oxford UK

Copy-opacity to cut out transparent mask -composite problems

Post by weatherbadger »

Hi

I'm trying to cut out a transparent mask-hole in my wave charts so an underlying land-map will show through in a web-browser.

I'm starting with http://www.weatherbadger.com/Charts/test/wave2.png

and have a landmask http://www.weatherbadger.com/Charts/tes ... transp.png - if you open this with GIMP you can see the land is transparent.

These two images are the same height but the wave2.png is slightly wider - with a colorbar on the right hand side.

I've got as far as:

Code: Select all

convert wave2.png wave_transp.png -compose copy-opacity -composite wave-no_cbar.png
which works BUT it is making the right hand side of the wave2.png transparent which cuts off the color-bar: http://www.weatherbadger.com/Charts/tes ... o_cbar.png
It would appear that my -composite is making everything outside the mask image tranparent also.

I've tried -gravity west but think I'm probably not using -composite right. I can change the landmask to a black rather than transparent image if that helps

Thanks for any suggestions.

WB
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Copy-opacity to cut out transparent mask -composite prob

Post by snibgo »

You can give a third image that will limit the dimensions of the composite. As you want this limit to be the source image you can simply clone it:

convert wave2.png wave_transp.png +clone -compose copy-opacity -composite wave-with_cbar.png
snibgo's IM pages: im.snibgo.com
weatherbadger
Posts: 15
Joined: 2010-03-01T09:52:50-07:00
Authentication code: 8675308
Location: Oxford UK

Re: Copy-opacity to cut out transparent mask -composite prob

Post by weatherbadger »

+Clone - I've never have come up with that.

Just tried it and it works. Brilliant.

Many thanks
WB
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Copy-opacity to cut out transparent mask -composite prob

Post by snibgo »

Good stuff. Send a bit of sunshine over towards Cambridge, would you?

"-gravity West" shouldn't make any difference. The default is NorthWest, but your source and destination images are the same height so NorthWest, West and SouthWest should give the same result.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Copy-opacity to cut out transparent mask -composite prob

Post by anthony »

weatherbadger wrote:Hi

I'm trying to cut out a transparent mask-hole in my wave charts so an underlying land-map will show through in a web-browser.

I'm starting with http://www.weatherbadger.com/Charts/test/wave2.png

and have a landmask http://www.weatherbadger.com/Charts/tes ... transp.png - if you open this with GIMP you can see the land is transparent.
As the images already has transparency, then you want to use a duff-porter composition.
http://www.imagemagick.org/Usage/compose/#duff-porter

The composition names make it very obvious as to pick what compose method you want to use.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply