Page 1 of 1

Adjust opacity leaving fully transparent sections unchanged

Posted: 2016-06-07T13:13:15-07:00
by pjfingers
Hello!

I have what seems to be a super simple task, yet I have spent hours looking through this forum as well as the IM docs trying to find a solution. Having tried 100s of variations I am still stumped. :shock:

I am starting with a PNG image (it's a map tile) that has areas full of color and a transparent background everywhere else:

https://www.dropbox.com/s/4ssdbehbbl0mm ... c.png?dl=0

I want to adjust the transparency of the colorful area, making it more transparent. When I run the command I have assembled I succeed in setting the transparency of the colorful section, however it also sets the previously totally transparent sections to the new level as well making those areas less transparent and filling in a gray background.

Code: Select all

convert pre-opac.png -channel A -evaluate set 39% post-opac.png
yeilds:

https://www.dropbox.com/s/01crbvjyvza9c ... c.png?dl=0

Looking at my code, it makes sense. As I read it, I'm setting the Alpha channel to 39% everywhere. So how can I dial down the opacity across the board so that the 0 areas stay at 0 and everything else comes down 39%?

I'm running
Version: ImageMagick 6.7.2-7 2015-02-27 Q16 http://www.imagemagick.org
OS: RHEL 6 x86_64

Re: Adjust opacity leaving fully transparent sections unchanged

Posted: 2016-06-07T15:56:18-07:00
by snibgo
Perhaps multiplying by 0.39 does what you want.

Re: Adjust opacity leaving fully transparent sections unchanged

Posted: 2016-07-17T08:04:44-07:00
by audas
Wow - I wish someone would answer this question as it is a real problem.

I have spent all day on this very issue. Heartbreaking stuff.

Even assigning a specific colour and then trying to remove it does not work. If someone has ANY idea on what to do here it would be a great help - this is something that REALLY should be addressed in the docs. There is literally no way of reducing the opacity of a colour bounded by transparency without raising the transparency of the (transparency) masked area.

Seems crazy.

Re: Adjust opacity leaving fully transparent sections unchanged

Posted: 2016-07-17T08:21:58-07:00
by snibgo
Didn't I answer the question? Multiply the alpha by whatever factor you want.

Code: Select all

convert in.png -channel A -evaluate Multiply 0.39 +channel out.png
Where the alpha was zero (transparent), it remains zero. Where it was one (opaque), it becomes 0.39 (mostly transparent). Etc.

Re: Adjust opacity leaving fully transparent sections unchanged

Posted: 2016-07-18T08:44:24-07:00
by pjfingers
Yep, multiply by desired opacity works great! Thanks for posting that one! 8)

I also figured out a second solution as follows:

Code: Select all

convert in.png -channel A +level 39%,100% out.png
Both work. The multiply opacity solution seems a little more obvious for anyone visiting the code in the future, so I went with that one in the end.