Passing Values to G'MIC Script

Hi,
In the past I’ve used DOS BAT files to invoke G’MIC commands and specified the image filename as a part of the command line call to the BAT file. I am wondering if the same can be done with G’MIC scripts? Following is an example, using BAT parameter standards - which don’t work here.
In this case my command line would be:
gmic testing.gmic doit inputfilename jpeg

# testing.gmic test script
#-------------------------------------------------
doit : 
echo "Starting" 
-input %1.%2
split c  
output[0] %1xchan0.jpg
output[1] %1xchan1.jpg 
output[2] %1xchan2.jpg
echo "Done"

When I run this I get the following error :
[gmic] *** Error in ./doit/ *** Command ‘input’: Unknown filename ‘%1.%2’.

which I rather expected since there’s no reason to think that a G’MIC script would work the same way as a DOS BAT script. In fact, can parameters even be passed in to G’MIC scripts?

Thanks.

Generally, I would use a for-loop in CMD.exe with more advanced file name and extension substitutions, or better yet, loop a self-contained gmic command.

Hi Afre,
Unfortunately I do not follow your answer at all. Let me restate the problem.
I have the following G’MIC script in a file named test.gmic:

# test.gmic
doit : 
-input thefile.jpg
-split c  
-output[0] thefile-chan0.jpg

From the DOS command prompt I can issue the following command:
gmic test.gmic doit

This works.

But what I want to do is replace the explicit filename “thefile.jpg” with a variable that takes its value from an argument passed in from the command line - just like I currently do when using a BAT program to execute a G’MIC command. This way I can reuse the same script for any image file versus having to create a unique script for every image I may want to process.

First question: is it even possible to pass a value from the DOS command line to the test.gmic script?

Second question: If the answer to the above question is yes, then how do I do it? Note that I did search through the G’MIC doc but was not able to find any references.

Bonjour,
An example …

set MyImage=test.jpg
set Dimension=300
echo %Dimension%,%Dimension%,1,3,u(255) fractalize. 0.1 blur. {%Dimension%/200} o. %MyImage% > test.gmic
gmic test.gmic
start %MyImage%


Example 2

set MyImage=test2.jpg
set Dimension=400
echo MyScript : %Dimension%,%Dimension%,1,3,u(255) fractalize. 0.1 > test2.gmic
gmic m test2.gmic MyScript o. %MyImage%
gmic %MyImage%

1 Like

Hi Samj,
First let me say I’m a fan of the filters you’ve contributed to G’MIC so thank you for that.

Unfortunately your solution above does not work for the problem I have. Also, what is in your test.gmic and test2.gmic files?

For me, a solution would be to show me the DOS command line statement(s) and the changes made to my test.gmic script file that makes it possible for me to, from the DOS command prompt, pass the name of an existing file to the gmic script that the script would then process.

I don’t understand exactly what you want :o(

To find what is in the ‘test.gmic’ and ‘test2.gmic’ files you have to understand how the ‘echo’ command works in my examples …
For example, you can edit these 2 files after each ‘echo’ command.


To make an example with your ‘doit :’ you save the following lines in the test3.gmic file

JimPlaxcoDoIt :
input $1
split c
output $2

To check :

gmic update
gmic sample lion o Source.jpg
set ImgIn=Source.jpg
set ImgOut=Result.jpg
gmic m test3.gmic JimPlaxcoDoIt %ImgIn%,%ImgOut%

test3.7z (181 Bytes)

Result_000000

Result_000001

Result_000002

1 Like

Hi Samj,
Got it. You made it clear what needed to be done. Here is a solution that works - though I had hoped to be able to do the execution as a single command.

Contents of the file go.gmic:

doit : 
echo "start"
echo $1
-input $1
split c  
output[0] $1-c0.tif
echo "All Done"

and the DOS command line i/o

D:\gmictesting>set iin=thefile.jpg
D:\gmictesting>gmic m go.gmic doit %iin%
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Import commands from file 'go.gmic' (1 new, total: 4511).
[gmic]-0./doit/ start
[gmic]-0./doit/ thefile.jpg
[gmic]-3./doit/ All Done
[gmic]-3./ End G'MIC interpreter.

I couldn’t have got here without your help. Many thanks. Jim

3 Likes

I’m glad you found a solution :o)

1 Like