Convert color bmp always to White & Black not to B&W

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?".
Konrad B
Posts: 10
Joined: 2017-02-25T12:47:24-07:00
Authentication code: 1151

Re: Convert color bmp always to White & Black not to B&W

Post by Konrad B »

I found out, that the filter setting "-blur 0x1" dont works with IM 6.8.9-9

With this code:

Code: Select all

convert 20701-2757.bmp -colorspace gray -auto-level -threshold 50% -level 0x50% result.bmp
(without filter "-blur 0x1") the bmp file (result.bmp) was created - but the background was black.
http://bogx.de/media/result.bmp
I need background white and foreground black (= invert of the result above).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert color bmp always to White & Black not to B&W

Post by snibgo »

I think Konrad B wants a binary output, with black and white only. If so, then antiliasing isn't needed, so "-blur" isn't needed.
Konrad B wrote:I need background white and foreground black (= invert of the result above).
Then put "-negate" before the final output filename.
snibgo's IM pages: im.snibgo.com
Konrad B
Posts: 10
Joined: 2017-02-25T12:47:24-07:00
Authentication code: 1151

Re: Convert color bmp always to White & Black not to B&W

Post by Konrad B »

Thanks guys!

I have the solution for PHP environment especially for my problem (to have always white background in 1-bit images) - is very simple:

Code: Select all

exec("convert input.png -monochrome -colors 2 result.bmp");
$color=exec('convert result.bmp -format "%[pixel: u.p{0,0}]" info:');
if ($color == 'black') {
 exec("convert result.bmp -negate result.bmp");	
}

Best regards,
Konrad
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert color bmp always to White & Black not to B&W

Post by snibgo »

snibgo wrote:How do you define "background"?
You have decided that the pixel at (0,0) is always background. Fine.
snibgo's IM pages: im.snibgo.com
Konrad B
Posts: 10
Joined: 2017-02-25T12:47:24-07:00
Authentication code: 1151

Re: Convert color bmp always to White & Black not to B&W

Post by Konrad B »

You have decided that the pixel at (0,0) is always background. Fine.
yes - exactly - all images have solid backgrounds in this project and are therefore very simple bitmaps ;-)

Best regards,
Konrad
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert color bmp always to White & Black not to B&W

Post by fmw42 »

Konrad B wrote: 2017-02-26T03:35:11-07:00 convert 20701-2756.bmp -colorspace gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result_2.bmp

Result:
line 2 dont works - no file (result_2.bmp) is created :-(
It works fine for me on IM 6.9.7.10 Q16 Mac OSX.

What do you mean by:
no file (result_2.bmp) is created
Post Reply