Linux 如何通过命令行将图像转换为灰度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7708368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:34:58  来源:igfitidea点击:

How can I convert an image to grayscale via the command line?

linuximagecommand-linesips

提问by cwd

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

如何使用sipsimagemagic或其他工具通过命令行将图像转换为黑白(灰度)?

采纳答案by mark

If you have imagemagickinstalled,

如果你已经imagemagick安装,

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.

如果您不在乎丢失原始文件:mogrify -colorspace Gray file.

回答by imm

use one of: -monochromeor -colorspace grayoptions for imagemagick(convert).

使用以下选项之一:-monochrome或( )-colorspace gray选项。imagemagickconvert