5

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

Celada
  • 21,627
  • 4
  • 64
  • 78
Mtrompe
  • 351
  • 5
  • 15
  • I know you want "shell script" - but please don't -either use GIMP's built-in Python-script (but I don't know if it works on OS X), or GIMP's script-fu, which is schema based. Doing this from an external shell process, just for start, could create a new GIMP process per image - thats is not what you want – jsbueno Jul 08 '13 at 15:24

1 Answers1

7

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

Mtrompe
  • 351
  • 5
  • 15
  • Changing hte value of '(0 0 0) changes the color to be left as transparent – Mtrompe Jul 08 '13 at 16:56
  • NOTE: `let`, `gimp-image-active-drawable`, `gimp-file-save` are instructions required for main command to work properly. `image` and `drawable` are internal variables that point to the currently loaded image. To run any other command replace `(plug-in-colortoalpha 1 image drawable '(0 0 0) )` with the correct command enclosed within braces. Check this link for info on the syntax: https://www.gimp.org/tutorials/Basic_Scheme/ – mccbala Jan 04 '16 at 11:49