How to apply gmic CLI

Question from a programming green
How to Install (CLI) gmic in Windows 11?
and how to apply correctly ?

It couldn’t be simpler.

To “install”:

To use:

  • Open your favorite terminal (cmd.exe maybe), then go to the folder containing gmic.exe.
  • You can now execute gmic.exe, e.g. gmic.exe sample david :slight_smile:

You could add it into path, so you can use it everywhere. My CLI path starts on system32, so I don’t mess with my gmic-community work.

Then Start Here.

1 Like

:slight_smile: hank you sincerely for your advice - I am starting the experience.

I have a folder and in it are several photos.
In this folder, I placed the gmic folder (renamed from pbranego gmic_3.5.0_cli_win64)
Iter now I would like to learn how to use the G`MIC command from the clipboard, for batch editing.
Something is trying and going wrong.

By the way, at my 91 years, I’m taking care not to get rusty -:slight_smile:

Guess: What is ‘going wrong’ is that Windows 11 cannot find the gmic.exe executable.

Going on that guess, what @David_Tschumperle suggests and what you have done are not quite the same steps. @David_Tschumperle suggestion leads to gmic.exe being in the same folder as the images to be worked on. What you have done is placed the folder containing gmic.exe with the images to be worked on. So the gmic executable, in fact, is in a subfolder with respect to those images. When Windows tries to find commands, it first looks in the current directory. It won’t find gmic.exe because it is in a sub-folder. Nor will Windows look in any other folder save those which have been added to the PATH environmental variable.

Long term, what @Reptorian suggests is best. Put gmic.exe in any folder you choose, named any way you care to, though I would suggest ‘Local_Executables’ or some such. Then, open “Environment Variables” from System Properties, locate the “Path” variable under “System Variables”, edit it, and add the path to ‘Local_Executables’, separating it from the other paths with a semicolon. With success, Windows will follow your amended path and find gmic.exe wherever you may be in your file system.

I am not a regular Windows 11 user. Appreciate it if anyone smarter about Windows could sane-wash my answer.

If I understood correctly, follow the advice with attachments given by afre w:

I thought there was a method more accessible to ordinary bread eaters

1 Like

That was me replying to a specific command line question, in a bit more advanced context. If you have a one-off need, it should be fairly straightforward to do it in the Windows CMD (or even PowerShell) terminal window. Since you want to do multiple images, you’ll need a loop, and I’m not versed enough in the Windows tools to know that recipe off the top of my head.

Edit path gmic under user variables. - Yes
I copy the GMIC command to the clipboard and type it into cmd
I open the folder where I have the sample files and the cmd file.
I click cmd and for a blink the PowerShell window opens you can see the records and then nothing happens.

I have a question again what am I doing incorrectly, how should I do it ?

Hi,

the problem here lies with your use of the apply_files command.

apply_files:
      "filename_pattern",_"command",_first_frame>=0,
        _last_frame={ >=0 | -1:Last },_frame_step>=1,
        _output_filename

Your -fx_color_presets command should be the 2nd argument of the apply_files command. But something tells me that it is not intended to be used in your case, but more with image sequences from a video. I’ve never used this command myself so i don’t really know how it works.

If you don’t have too many images or you do have a lot of RAM you can try :
gmic *.png foreach -fx_color_presets [params...] -o {b}.jpg rm done
gmic input_glob "*.png" foreach -fx_color_presets [params...] -o {b}.jpg rm done
But again, i’ve never used G’mic for batch processing so there is surely a better way.
This will load all images into RAM at the beginning and then process each one individually (foreach), output it as original_name.jpg (-o {b}.jpg) and remove it from memory (rm) (so you gradually recover your ram).

2 Likes
gmic run '-input_glob '*.png' foreach { -echo {n} }'

could float your boat. Prints out the name of every PNG in the current directory. The space following the opening outer { and preceding the outer closing } has parsing significance and should be retained. -echo {n} is for demonstration purposes; replace it with something interesting. For me ‘Something interesting’ is a custom command that I’ve written that does whatever needs to be done to each PNG in the current directory.

G’MIC works best interactively in command shells. Suggest avoiding the MSDos batch file approach; G’MIC has loads of native iterative constructs; foreach is just one of them. Revisit Start Here, especially the first bit, which examines the anatomy of command lines.

Gotta tip. New York City calls.

1 Like

Mostly decent approach. Just this: -input doesn’t do file globbing. Consider -input_glob. See my other reply.

$ gmic run '*.jpg foreach { -echo {n} }'
[gmic]./ Start G'MIC interpreter (v.3.5.3).
[gmic]./run/__run/ Input file '*.jpg' at position 0
[gmic]./run/__run/ *** Error *** Command 'input': Unknown filename '*.jpg'.
1 Like

I see. Didn’t know this input_glob command.
i usually use run too on Linux, but not this time. And *.jpg works just fine without run. Anyway, i’ll just edit my answer, thanks!

EDIT: BTW, is there a way not to load all the images at the start? I’ve seen the files command which lists the filenames and/or folders from a directory and outputs it in status ${}, delimited by commas, but i don’t know what to do next.
Didn’t find the correct syntax to replace commas with spaces using strreplace either.

@Zbyma72age Try this, using cmd.exe:

  1. First, add gmic in your PATH:
> setx PATH "%PATH%;C:\path_to_your_gmic_folder\gmic-3.5.3-cli-win64

Then, close and restart cmd.exe.
Then go to your folder with all your pictures, and try this:

First create a subfolder name processed:

> mkdir processed

Then run gmic.exe to process your images:

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

where you can replace the blur 10 by any G’MIC pipeline you want (that takes one image as input, and output a single image).

3 Likes

Thank you very much.

The result was immediate, except that I had already set the path to gmic according to the recommendation given in:

Why I was so persistent with this idea.

Since I already wrote a tutorial => Batch editing in gimp_gmic_qt

and I found that it was too long and complicated a process, while there is simplicity and speed in this method.

I emphasize that I am not a programmer, but an amateur with 20 years of experience in G`MIC.

I have already written several guides in this regard.

Further it is my hobby to do something for others and not get rusty (I am 91 years old).

Thank you again

4 Likes

I have one more question;
If there are files with extension jpeg and jpg in the same folder then I have to use two scripts, or is there another method?
Or is there a method for all types of extensions in a folder ?

This should work:
Replace files *.jpg files=${} by

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

Again, thank you very much
But I have another inquiry:
How to integrate more complex processing, more commands from the clipboard?

Not sure what you mean by this. You may want to read the tutorials from @grosgood , it will teach you how G’MIC works in depth, and allow you to do almost everything you want with your images.

For example, can you paste in the same cmd, for example. two more commands from the clipboard