2

I want to non-interactively load an image into gimp from the command line without opening any window and exiting afterwards in Linux.

I have read gimp basic batch but still I am confusing. I appreciate any help.

2
  • 1
    Please expand your first paragraph into a few sentences.  When you say “non-interactively … from the command line”, do you mean a command (that you can run from the shell) that doesn’t have any dialog? Or is it OK if it has well-defined (predictable) dialog, which can be scripted?  What do you mean by “without opening any window”?  What do you mean by “and exiting afterwards”?  Please do not respond in comments; edit your question to make it clearer and more complete. Jun 26, 2018 at 17:02
  • See stackoverflow.com/questions/44430081/… (95% of it also applies to Linux)
    – xenoid
    Jun 26, 2018 at 22:02

1 Answer 1

1

If your goal is to automate image processing with Gimp's CLI, using its so-called Batch mode, there are three parts to this:

1. Open Gimp with no interface

This can be accomplished by include the -i option on any Gimp command(including batch mode)

2. Modify your image files and save them

This is accomplished in the form of a "Procedure" as Gimp puts it. There is a specific procedure for just about every possible action you can take on an image, from giving it a %50 sepia filter, to saving it as a bitmap image, to closing Gimp altogether. For every procedure that you want to run, you need to include a -b option in the command, then follow that with the specific procedure you want to execute. For an exhaustive list of all the procedures available to you, look in the procedure browser, which can be found by opening Gimp with the standard graphical interface, clicking on the Help menu item, then clicking on Procedure Browser. You can search and browse this list for what you want to do.

3. Quit Gimp automatically

To do this, you just execute the quit procedure: (gimp-quit 0)


Overview

To start, you can play around with a simplified version of all these steps. First cd to the directory which contains an image file you want to modify, then execute this command:

gimp <image-file.jpg> -i -b '(gimp-quit 0)'

Make sure to replace "image-file.jpg" with an actual image file in that directory. If it worked, you may just see some text briefly in your command line and then you'll have shell control returned to you after a second or so. In summary, this command:

  1. Opens an image as specified by the image file
  2. Opens it in "no-interface" mode with the -i option
  3. Then subsequently runs the gimp-quit procedure.

Now, in order to get a little more complicated and process several images at once, the documentation you mentioned includes Gimp-specific scripts(written in "Script-Fu") that you can save to help with automating this.

These scripts may look a little daunting but keep in mind it's just a combination of:

  • The aforementioned "procedures"
  • The script-fu scripting language(which itself should simple and intuitive to learn). See here for more about scripting in Gimp

You'll need to start familiarizing yourself with these in order to get comfortable enough to modify Gimp's provided scripts to achieve the kind of automation you're looking for. If you're feeling confused by it, start by doing little tests like the one I provided above and eventually you'll get more comfortable to the point you can batch process.

You can learn more about Script-Fu with Gimp's guide.

You must log in to answer this question.

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