9

I need to invert multiple .png images from black to white using command line.

I have found that I might use gimp plugin "plug-in-vinvert" but I can not figure out how to use it. I have tried something like

gimp -b '(plug-in-vinvert "INT32" "filename.png" "/resultsFolder/")'

and many other combinations but with no success.

3 Answers 3

21

Why gimp? Try imagemagick package. It's a great command line image processor. In your case you can use it like:

convert -negate src.png dst.png

To modify multiple files at once, e.g.

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

The exact method may depend on how you source your paths.

Here's an actual example...

$ 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
8
  • It works, except it converts only one file. Oct 26, 2014 at 16:53
  • 1
    Add loop: for i in `ls *.jpg`; do convert ${i%.*}.png ${i%.*}-inverted.png; done Oct 26, 2014 at 17:06
  • I have tried your code, but it is not working for me. I guess I am doing some stupid mistake, because I am quite new with Linux. I paste your code directly into terminal and when i press enter, all I get is ">". Oct 27, 2014 at 9:16
  • 1
    I was not working because I have copied it without the "done". You have there one small error, but the working code is for i in `ls *.png`; do convert -negate ${i%.*}.png results/${i%.*}.png; done I have just added -negate and changed the code to place the inverted images into "results" folder. Oct 28, 2014 at 22:38
  • 1
    Thanks. In that case the final code is for i in `ls *.png`; do convert -negate $i results/$i; done Oct 29, 2014 at 8:42
5

To convert a batch of images, the fastest and shortest way I know is to use the following ImageMagick command:

mogrify -negate *.jpg

N.B. Change image format accordingly and make sure you have a copy of the original images.

1
  • Thanks, perfect! For me, it was magick mogrify -negate *.png as mogrify does not seem to be a directly callable (archlinux)
    – bonanza
    Feb 3, 2019 at 15:19
1

Try this GIMP plugin for performing a routine on multiple images simultaneously: "Batch Image Manipulation Plugin" http://registry.gimp.org/node/26259

Download and extract the package, open a terminal inside the resulting folder, and run:

make && make install

Then start Gimp, go to File - Batch Image Manipulation, in order to start the plugin. There you can add the multiple images.

enter image description here

As the question asks for inverting colors, add the corresponding manipulation set: Add - Other GIMP procedure, search for 'invert' and you will find 'gimp-invert'

enter image description here

OK, and before 'Apply' you can set the output folder which by default is ~/.

Hope that helps. Have fun GIMPing!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .