How to apply gmic CLI

Hi,

if the result you are looking for is the the sum of multiple effects applied one after the other, then you just have to copy the settings from each effect like you did before (with the icon), and “pipeline” them into your script.
Here is @David_Tschumperle 's example from before with a few more commands thrown in :

> gmic.exe v - files *.jpg files=${} repeat narg($files) { arg0 "$>,$files" file=${} v + e $file v - l[] { $file name={b} blur 10 normalize_local 8,10 sharpen 500 o processed/$name.jpg,85 rm } }

Just paste your “fx_…” one by one between $file name={b} and o processed...

Yes. But at some point, when you add more and more commands, it’ll be probably preferable to put them in a “commands.gmic” file in the same fashion you can find in this forum:

command_name:
  blur 10
  normalize_local 8,10
  sharpen 500

You can even create multiple commands in the same file and call them from your batch file.

gmic.exe path\to\file.gmic command_name

Not working

I tried it out immediately it works great - Thank you

Ha, because of the use of && probably. This should work:

files *.jpg files=${} files *.jpeg if "narg($files)&&narg(${})" files.=,${} else files=${} fi

that’s specific to cmd though.

Ok now it works Thanks

1 Like

Here maybe a silly question, where should you put command_name ?

If you kept the original line designed by David, you have to write the filename of the .gmic file just after gmic.exe, and then call the “command_name” ( or whatever name you gave it) where you did put your FX commands before ( it should replace them or else they’ll be applied twice, once by the file, once directly by the gmic line ).
I’m on my phone it’s a bit tricky to write, so sorry if I sound unclear.

Sorry but I didn’t understand
I have the gmic CLI installed in C:\gmic
Where to place the file: command_name
How do I write a path to: command_name

No, to be more precise, you have to create a file user.gmic in your folder %HOMEPATH% (which is actually C:\Users\david\ for me, on Win7).
This is a simple text file (ASCII), that contains your custom commands, e.g.

# File 'user.gmic': Define some custom commands for G'MIC.
#
my_command :  check "$1>0"
  blur $1 mirror x sharpen 500

(Beware: the file extension must be .gmic, not .gmic.txt or anything else, sometimes file extensions are not displayed in the Windows file explorer).

Now, everytimes you use gmic.exe, it will recognize your custom command:

So you can use your command in any G’MIC pipeline you want.

[quote=“David_Tschumperle, post:30, topic:48838”]
Thank you I have it:

but I don’t know how to apply

Now, everytimes you use **gmic.exe**, it will recognize your custom command:

In your screenshot your command is named “command_name”, so you can call it just by typing:
gmic.exe an_image.png command_name

This name was just an example, you should change it to something more representative ( without spaces).
You can also add as many commands as you want in this file, as long as you give them different names ( obviously).

Sad, but I still do not know how to apply,
gmic.exe an_image.png command_name
Please understand that I am not a computer scientist only self-taught, and programming green

Should I call this in Windows PowerShell
and as I wrote above
I have a need to change all the files in a folder = batch edit.

We’re on the same boat!

Can you copy your current code here? And provide a screenshot of your folder so i know where the files are.

“your current code here” is in the screenshot above.
Folder with e.g. 4 photos I placed on the Desktop.

Hi Zbyszek.

Sorry, not entirely on topic.
A much simpler tool, also for batch conversion (and better than BIMP, e.g. saving/loading settings, arbitrary change of procedure order) is Kamil Burda’s Batcher (equivalent of Export Layers for Gimp-3.0.0).

I tested it in Gimp-3.0.0 (after fixing Python support) and it works very well.

It has an extensive user manual (maybe you could translate it?) and the ability to Polonize the interface.

Hi MareroQ
I have both versions for GIMP 2.10 and 3.0.0 they work great, maybe with too small Preview window.
I have provided links to various current GIMP 3.0 plug-ins on the PL pages.
My intention is to learn the CLI.
The CLI is often much more efficient than the GUI equivalent.

1 Like

Yes, or the windows command prompt, if gmic.exe is in your path.
You can also call it from a .cmd file too.
Creating commands in the user.gmic file make them available to G’MIC like regular commands.
So in your batch .cmd file it should be like this :

> gmic.exe v - files *.jpg files=${} files *.jpeg if "narg($files)&&narg(${})" files.=,${} else files=${} fi
 repeat narg($files) { arg0 "$>,$files" file=${} v + e $file v - l[] { $file name={b} command_name o processed/$name.jpg,85 rm } }

Can I see output of ‘gmic version’ in CLI? Should look like this:

C:\Windows\System32>gmic version

  gmic: GREYC's Magic for Image Computing: Command-line interface
        Version 3.5.3 (pre-release #25021410)
        (https://gmic.eu)

        Copyright (c) 2008-2025, David Tschumperlé / GREYC / CNRS.
        (https://www.greyc.fr)

Should I call this in Windows PowerShell

Yes, Either PowerShell or call the command through the basic Microsoft Command Prompt, also a shell, but a less capable one. Either will do, but I will assume the Command Prompt as that is always available.

The gmic “user experience” is very different from that of "gmic-qt". The latter is a “container” of G’MIC scripts and aims to interact with some host paint program ( as a plug-in extension ) to make those scripts available as “filters” to paint program users. When built (compiled) in a somewhat different way, gmic-qt can also operate, “standalone”, as a command which may be called from a shell. “gmic-qt” furnishes a way for shell-users to access paint-program filters based on G’MIC. That capability is not otherwise pertinent to this discussion.

Please understand that I am not a computer scientist only self-taught, and programming green

Alas! gmic — in contrast to gmic-qtis a ‘command line interpreter (CLI)’ that interprets “pipelines” — sequences of G’MIC commands — and the building of pipelines is essentially a programming craft. Further, gmic is designed to operate in a shell — all of my (in)famous tutorials simply presume that setting.

The gmic-qt plug-in does furnish Custom Code filters in the Various section; it is handy for writing small G’MIC pipelines so as to obtain a sense of how they operate in a paint-program setting. I do not recommend this setting for writing (and investigating) anything other than short, simple pipelines.

Now, you may not care to spend that much time programming pipelines. Understandable, But the advice being offered here runs along pipeline programming lines. I wager that you are capable enough to follows those lines in a very basic way. Let’s make sure that you can.

First, confirm that gmic.exe can be called in whatever current directory that your command prompt is operating in. Skip past this procedure if you are assured that gmic is in your Windows PATH and that you can invoke gmic.exe from any folder/directory.

From your Windows 10/11 desktop:

  1. Type “Command” in the desktop Search field, lower panel.
  2. Windows Search offers ‘Command Prompt’ as the primary result. Open it.
  3. In a couple or three seconds Windows opens a command prompt window.
  4. Among other initial indicators, there is a line consisting of a path, which typically starts with a drive letter and proceeds through a sequence of folder names, these separated by back slashes "". This preamble tells you the path to your current working folder (directory). This becomes the operating context of the Command Prompt. This sequence ends with a “>” character and a flashing prompt.
  5. At this flashing prompt, type gmic.exe.
  6. This may fail with the Command Prompt reporting: "'gmic.exe' is not recognized as an internal or external command, operable program or batch file." You need to add the folder containing the gmic.exe program to the Windows path; see previous posts on that topic.
  7. Or, the gmic.exe is indeed on your path and it prints its own preamble. Among other things, it complains: "[gmic] No commands, options or data provided." You haven’t given gmic a pipeline to work on. Of course, you are very keen on providing that pipeline.

One of the most important G’MIC features (my opinion: of first importance!) is that it can be extended with “custom commands.” Indeed, the majority of the nine hundred or so commands that the out-of-the-box G’MIC interpreter knows how to perform are custom commands - G’MIC scripts written along this general scheme:

<name> : <pipeline>
<empty line>
<name> : <pipeline>
<empty line>
       .
       .
       .

The prose in <angle brackets> describe what is to be written; do not literally write <name> but write a brief bit of plain text, beginning with a letter and excluding all white space, that is descriptive of an action. That becomes the name of the custom command. The colon : is the one literal character to be written here. It’s job is to designate the left hand as the key needed to fetch the righthand <pipeline>, a G’MIC pipeline.

During the course of its execution, gmic.exe encounters custom command names; it employs the encountered name to fetch predefined pipelines. Any custom commands that you write need to go in a place where the G’MIC can find them.

One such place is %USERPROFILE%\user.gmic. %USERPROFILE% is a pre-defined Windows environment variable designating a path that varies from one Windows installation to another. user.gmic is a text file intended to contain custom command definitions. The format of user.gmic follows the rules given in Adding Custom Commands.

  1. Write the text file, %USERPROFILE%\user.gmic`

  2. Within that text file, define a custom command <name> : <pipeline> The left hand side of : becomes the name of the custom command. The right hand side of : establishes what the command does - Or, in your case, the G’MIC commands that you want to apply to your images.

  3. Ensure that G’MIC can find your command and that it works as expected. Bring up a Command Prompt and change directory to the folder where your image files are. Then, at the blinking prompt write: >gmic.exe -input <some file>.<some extension> <your custom command name>. Recall that whatever I write in angle brackets is descriptive of what you write; it is not to be literally transcribed!

  4. You will likely repeat step 3. a number of times before you find the sequence of commands that furnish the results you desire, and you resolve various pipeline syntax errors that always plague ‘green programmers.’ You will be modifying your custom command in %USERPROFILE%\user.gmic` a number of times. Keep calm and carry on.

  5. In Post 14 @David_Tschumperle furnishes the setting for batch work that does not make excessive memory demands. Replace his demonstration command, blur 10, with your custom command, once you are satisfied that it operates as expected.

Hope this helps.

1 Like