Page 2 of 2
Re: Convert color bmp always to White & Black not to B&W
Posted: 2017-02-26T04:06:09-07:00
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).
Re: Convert color bmp always to White & Black not to B&W
Posted: 2017-02-26T09:17:03-07:00
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.
Re: Convert color bmp always to White & Black not to B&W
Posted: 2017-02-26T09:24:11-07:00
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
Re: Convert color bmp always to White & Black not to B&W
Posted: 2017-02-26T09:35:23-07:00
by snibgo
snibgo wrote:How do you define "background"?
You have decided that the pixel at (0,0) is always background. Fine.
Re: Convert color bmp always to White & Black not to B&W
Posted: 2017-02-26T09:42:13-07:00
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
Re: Convert color bmp always to White & Black not to B&W
Posted: 2017-03-06T16:13:12-07:00
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