ImageMagick(PerlMagick) でモノクロビットマップを作る

あんまりやる機会はなさそうだけど、メモ

convert image.png -colors 2 +dither -type bilevel image.bmp

こうやるらしい。 最初 -type Bilevel だけでやっていたら、色は確かに減るんだけどサイズは減らない(24bppになっていた)。逆に -colors 2 だけでもだめで、このときは 32bpp にむしろなってそうだった。両方つけると1bppのbmpが出来上がる。

これを PerlMagick でやろうとすると

$image->Read($input_name);
$image->Set(type => 'Bilevel');
$image->Quantize(colors => 2);
$image->Write($output_name);

こうなる。