Page 1 of 1

How to convert a transparent PNG to black & white?

Posted: 2020-05-02T12:38:11-07:00
by etrader
I want to convert a transparent PNG to a black silhouette. This means the transparent part should remain transparent (or white), the non-transparent part should be transformed into pure black by losing all textures.

I tried -threshold 0%, but it retains some texture, as it turns the non-transparent to white.

Re: How to convert a transparent PNG to black & white?

Posted: 2020-05-02T13:42:42-07:00
by snibgo
What version of IM, on what platform? Please provide a sample input.

What does "by losing all textures" mean?

Re: How to convert a transparent PNG to black & white?

Posted: 2020-05-02T13:48:35-07:00
by fmw42
Post an example input and a mockup of your desired output. What version of ImageMagick and what platform/OS are you using?

Try (IM 6)

Code: Select all

convert transparent_image.png -fill black +opaque none result.jpg
If on IM 7, replace convert with magick.

Re: How to convert a transparent PNG to black & white?

Posted: 2020-05-02T14:10:34-07:00
by etrader
snibgo wrote:
2020-05-02T13:42:42-07:00
What version of IM, on what platform? Please provide a sample input.

What does "by losing all textures" mean?
Sorry for not providing my system information.
Version: ImageMagick 7.0.8-34 Q16 x86_64 2019-03-18
Ubuntu 18.04

I want to turn the non-transparent part of PNG to pitch black with no texture (not grey).

It is not about a specific input. Take any transparent PNG for example.
fmw42 wrote:
2020-05-02T13:48:35-07:00
Post an example input and a mockup of your desired output. What version of ImageMagick and what platform/OS are you using?

Try (IM 6)

Code: Select all

convert transparent_image.png -fill black +opaque none result.jpg
If on IM 7, replace convert with magick.
It did not work. It turns the whole picture to black (both transparent and non-transparent part).

By the way, what is the different/advantage of magick? I always use convert as an old habit.

Re: How to convert a transparent PNG to black & white?

Posted: 2020-05-02T14:27:08-07:00
by snibgo

Code: Select all

magick in.png -channel RGB -fill Black -colorize 100 +channel out.png
"magick" uses v7 syntax. "convert" uses v6 syntax.

V7 is better than v6.

Re: How to convert a transparent PNG to black & white?

Posted: 2020-05-02T15:34:42-07:00
by etrader
snibgo wrote:
2020-05-02T14:27:08-07:00

Code: Select all

magick in.png -channel RGB -fill Black -colorize 100 +channel out.png
it works beautifully.

Re: How to convert a transparent PNG to black & white?

Posted: 2020-05-02T16:10:54-07:00
by fmw42
This works fine for me on IM 7.0.10.10 Q16 Mac OSX

# create transparent image:

Code: Select all

magick logo: -transparent white logot.png
# process it:

Code: Select all

magick logot.png -fill black +opaque none logot_result.png