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).

Share:
63,539

Related videos on Youtube

cwd
Author by

cwd

Updated on May 23, 2020

Comments

  • cwd
    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
      Chiron over 3 years
      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.
  • C--
    C-- over 4 years
    None of these actually convert a AxBx3 RGB image into a AxBx1 single channel grayscale image though.
  • Tiago Franco
    Tiago Franco about 4 years
    The separate worked great for me.