112

How can I use sips, imagemagic, or another tool to convert an image to black and white (grayscale) via the command line?

cwd
  • 53,018
  • 53
  • 161
  • 198
  • Open built-in python: `from PIL import Image ; Image.open('a.png').convert('L').save('grey.png')` for those who prefer staying away from software installing. – Chiron Jan 20 '21 at 08:29

2 Answers2

197

If you have imagemagick installed,

convert source.jpg -colorspace Gray destination.jpg (true grayscale only)
convert source.jpg -monochrome destination.jpg (true black and white)
convert source.jpg -separate destination.jpg (separate into gray channels)

If you don't care about losing the original file: mogrify -colorspace Gray file.

Community
  • 1
  • 1
mark
  • 2,195
  • 1
  • 13
  • 8
  • 5
    None of these actually convert a `AxBx3` `RGB` image into a `AxBx1` single channel grayscale image though. – C-- Feb 03 '20 at 15:26
15

use one of: -monochrome or -colorspace gray options for imagemagick (convert).

imm
  • 5,837
  • 1
  • 26
  • 32