Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use gimp color-to-alpha script in a shell script

Tags:

shell

macos

gimp

I am trying to reproduce the color-to-alpha function gimp offer, which adds a level of transparency depending on the amount of color in a pixel.

The reason why I want to know how to use this function from a command line is to apply the function to many images in a single click without having to open each image one by one in gimp.

To run a gimp script from terminal, the following line is used : /Applications/GIMP.app/Contents/MacOS/gimp -i -b followed by the name of the function and its arguments.

This function is called color-to-alpha and takes 4 arguments to work which are the following:

run-mode INT32 Interactive, non-interactive
image IMAGE imput image
drawable DRAWABLE input drawable
color COLOR Color to remove

So I have tried the following: /Applications/GIMP.app/Contents/MacOS/gimp -i -b '(color-to-alpha 0 "/Users/Maxime/Desktop/Images/fx_ice.png" 0 (0 0 0))' -b '(gimp-quit 0)' but I have the following error: Error: ( : 2) eval: unbound variable: color-to-alpha

I'am guessing the problem comes from the syntax of the arguments I am trying to pass. I have tried to find example of how to pass arguments like in this case but have not found anything.

If someone knew how to do this, it would be great,

Thank you

like image 204
Mtrompe Avatar asked Jul 07 '13 21:07

Mtrompe


1 Answers

Ok, I have found the awnser to my post.

What I was doing was pretty much wrong all the way :p

So here is a batch command line that removes black baground from an image like the color-to-alpha function of GIMP :

/Applications/GIMP.app/Contents/MacOS/gimp -i -b "(let* ( ( image (car (file-png-load 1 \"/Users/Name/Desktop/img.png\" \"/Users/Name/Desktop/img.png\") ) ) (drawable (car (gimp-image-active-drawable image) ) ) ) (plug-in-colortoalpha 1 image drawable '(0 0 0) ) (gimp-file-save RUN-NONINTERACTIVE image drawable \"/Users/Name/Desktop/img2.png\" \"/Users/Name/Desktop/img2.png\") ) " -b "(gimp-quit 0)"

It is quite incomprehensive like this because it needs to be an inline command but it works fine on my MAC

like image 160
Mtrompe Avatar answered Oct 08 '22 12:10

Mtrompe