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

戏子无情 提交于 2019-12-07 07:42:54

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/17516624/use-gimp-color-to-alpha-script-in-a-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!