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 »

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: 12159
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 »

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 »

Thank you!
Great!! What's the +channel at the end for?
snibgo
Posts: 12159
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 »

"-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 »

Thanks! Great explanations :)
Post Reply