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!
Convert BMP to transparent PNG
-
- Posts: 2
- Joined: 2014-05-15T23:41:04-07:00
- Authentication code: 6789
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert BMP to transparent PNG
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:
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
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert BMP to transparent PNG
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert BMP to transparent PNG
Ah, brilliant, thanks. I thought I might be forgetting something.
snibgo's IM pages: im.snibgo.com
-
- Posts: 2
- Joined: 2014-05-15T23:41:04-07:00
- Authentication code: 6789
[Solved] Re: Convert BMP to transparent PNG
Thank you very much! Works great.