How can I use sips
, imagemagic
, or another tool to convert an image to black and white (grayscale) via the command line?
Asked
Active
Viewed 6.9k times
112

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 Answers
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
.
-
5None of these actually convert a `AxBx3` `RGB` image into a `AxBx1` single channel grayscale image though. – C-- Feb 03 '20 at 15:26