如何在终端中修改多个图像?

Jur*_*inc 8 command-line gimp convert png

我需要.png使用命令行将多个图像从黑色反转为白色。

我发现我可能会使用 gimp 插件“plug-in-vinvert”,但我不知道如何使用它。我试过类似的东西

gimp -b '(plug-in-vinvert "INT32" "filename.png" "/resultsFolder/")'
Run Code Online (Sandbox Code Playgroud)

和许多其他组合,但没有成功。

Ohm*_*tor 20

为什么是 gimp?试试imagemagick包。这是一个很棒的命令行图像处理器。在您的情况下,您可以像这样使用它:

convert -negate src.png dst.png
Run Code Online (Sandbox Code Playgroud)

一次修改多个文件,例如

img_path=./path/to/imgs
img_results=./path/to/imgs/results
mkdir -p $img_results
for img in ${img_path}/*;
    do 
    convert -negate $img ${img_results}/${img#./*};
done
Run Code Online (Sandbox Code Playgroud)

确切的方法可能取决于您如何获取路径。

这是一个实际的例子......

$ for img in ./png-64/*; do echo convert -negate $img results/${img#./*}; done
convert -negate ./png-64/arrow-block.png results/png-64/arrow-block.png
convert -negate ./png-64/arrow-block-rotated.png results/png-64/arrow-block-rotated.png
convert -negate ./png-64/arrow-shrink.png results/png-64/arrow-shrink.png
Run Code Online (Sandbox Code Playgroud)


Dev*_*hon 5

转换一批图像,我知道的最快、最短的方法是使用以下ImageMagick命令:

mogrify -negate *.jpg
Run Code Online (Sandbox Code Playgroud)

注意相应地更改图像格式并确保您拥有原始图像的副本。