How can I convert an image to grayscale via the command line?
63,539
Solution 1
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
.
Solution 2
use one of: -monochrome
or -colorspace gray
options for imagemagick
(convert
).
Related videos on Youtube
Author by
cwd
Updated on May 23, 2020Comments
-
cwd almost 4 years
How can I use
sips
,imagemagic
, or another tool to convert an image to black and white (grayscale) via the command line?-
Chiron over 3 yearsOpen 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.
-
-
C-- over 4 yearsNone of these actually convert a
AxBx3
RGB
image into aAxBx1
single channel grayscale image though. -
Tiago Franco about 4 yearsThe separate worked great for me.