Page 1 of 1
Convert BMP to transparent PNG
Posted: 2014-05-16T03:12:30-07:00
by Markus Breitinger
I have a collection of Windows BMP files which use the color of upper left corner to define the transparent background. The target should be PNG files.
I tried:
convert MOT01_MOT_AP_GROSS_AUS.bmp -transparent %[pixel:p{0,0}] MOT01_MOT_AP_GROSS_AUS.png
but somehow it is wrong. Could you please help me!
Re: Convert BMP to transparent PNG
Posted: 2014-05-16T06:01:38-07:00
by snibgo
Sadly, "-transparent" needs an actual colour, and can't accept a "pixel:" expression.
I don't think this can be done in a single convert. We can do it in two converts. The first gets the colour. For example, Windows BAT format:
Code: Select all
for /F "usebackq" %%C ^
in (`%IM%convert x.bmp -format "%%[pixel:p{0,0}]" info:`) ^
do set ONE_PIXEL=%%C
%IM%convert x.bmp -transparent %ONE_PIXEL% x.png
Re: Convert BMP to transparent PNG
Posted: 2014-05-16T21:47:29-07:00
by fmw42
there is a way to do the equivalent in one command. you can even add -fuzz XX% if you want
Code: Select all
convert image.bmp -fill none -draw "matte 0,0 replace" newimage.png
Re: Convert BMP to transparent PNG
Posted: 2014-05-17T02:49:50-07:00
by snibgo
Ah, brilliant, thanks. I thought I might be forgetting something.
[Solved] Re: Convert BMP to transparent PNG
Posted: 2014-05-19T01:59:52-07:00
by Markus Breitinger
Thank you very much! Works great.