How do I convert a JPG into a 50% transparent PNG?

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
xberg
Posts: 13
Joined: 2017-11-23T03:02:10-07:00
Authentication code: 1152

How do I convert a JPG into a 50% transparent PNG?

Post by xberg » 2017-12-22T01:23:59-07:00

Hi,

I want to transform any JPG into a 50% transparent PNG.
I found how to make a specific color fully transparent with:

Code: Select all

magick convert 1.jpg -fuzz 8%% -transparent white 1.png
But I don't want this: I want all the JPG to be a 50% opaque PNG.

Thanks

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

Re: How do I convert a JPG into a 50% transparent PNG?

Post by snibgo » 2017-12-22T01:44:11-07:00

Code: Select all

magick in.jpg -alpha set -channel A -evaluate set 50% +channel out.png
snibgo's IM pages: im.snibgo.com

xberg
Posts: 13
Joined: 2017-11-23T03:02:10-07:00
Authentication code: 1152

Re: How do I convert a JPG into a 50% transparent PNG?

Post by xberg » 2017-12-22T01:47:17-07:00

Thank you!
Great!! What's the +channel at the end for?

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

Re: How do I convert a JPG into a 50% transparent PNG?

Post by snibgo » 2017-12-22T02:05:53-07:00

"-channel A" means "apply all following operations to just the Alpha channel". "+channel" means "set the default, which is that all following operations apply to all channels".

In this case it is superfluous, but good practice is: whenever you have a "-channel", you should always have a "+channel" somewhere.
snibgo's IM pages: im.snibgo.com

xberg
Posts: 13
Joined: 2017-11-23T03:02:10-07:00
Authentication code: 1152

Re: How do I convert a JPG into a 50% transparent PNG?

Post by xberg » 2017-12-22T02:18:17-07:00

Thanks! Great explanations :)

Post Reply