G'MIC Tutorial Fragments

On branch: master: 6ff2638

Tutorial Upgrades for June 3, 2023. Significant changes:

  • inout/shared.gmd - migration of -shared command tutorial from 1.6,
    retiring the old command. New example and a revised discussion on
    the mapping between command arguments and the kinds of contiguous
    buffers that arise from various sets of arguments.

Other bits are in the works, but not until mid-June. Enjoy!

1 Like

@grosgood
Merci :o)

For information the result of some tests on documentation
from

to


https://gmic.eu/reference/display_parametric.html#top
replace
gmic 1024,1,1,2,'t=x/40;if(c==0,sin(t),cos(t))*(exp(cos(t))-2*cos(4*t)-sin(t/12)^5)' display_parametric 512,512
by
gmic 1024,1,1,2,"t=x/40;if(c==0,sin(t),cos(t))*(exp(cos(t))-2*cos(4*t)-sin(t/12)^5)" display_parametric 512,512



https://gmic.eu/reference/display_quiver.html#top
replace
gmic image.jpg +luminance gradient[-1] xy rv[-2,-1] *[-2] -1 a[-2,-1] c crop 60,10,90,30 +display_quiver[1] ,
by
gmic image.jpg +luminance gradient[-1] xy rv[-2,-1] *[-2] -1 a[-2,-1] c crop 60,10,90,30 +display_quiver[1]



https://gmic.eu/reference/input.html#top

do not work under Linux
gmic input test 5*5(1,2,3;4,5,6;7,8,9^9,8,7;6,5,4;3,2,1)
gmic image.jpg (1,2,3;4,5,6;7,8,9) (255^128^64) 400,400,1,3,'(x>w/2?x:y)*c'

The renderings are bad under windows
replace
gmic image.jpg (1,2,3;4,5,6;7,8,9) (255^128^64) 400,400,1,3,'(x>w/2?x:y)*c'
by
gmic image.jpg (1,2,3;4,5,6;7,8,9) (255^128^64) 400,400,1,3,"(x>w/2?x:y)*c"



https://gmic.eu/reference/pass.html#top
replace
gmic command "average : pass$""1 add[^-1] [-1] remove[-1] div 2" sample ? +mirror y +average[0] [1]
by
gmic command "average : pass$\"\"1 add[^-1] [-1] remove[-1] div 2" sample ? +mirror y +average[0] [1]



https://gmic.eu/reference/shape_circle.html#top
replace
gmic shape_circle ,
by
gmic shape_circle


https://gmic.eu/reference/shape_cupid.html#top
replace
gmic shape_cupid ,
by
gmic shape_cupid


https://gmic.eu/reference/shape_diamond.html#top
replace
gmic shape_diamond ,
by
gmic shape_diamond


https://gmic.eu/reference/shape_dragon.html#top
replace
gmic shape_dragon ,
by
gmic shape_dragon


https://gmic.eu/reference/shape_fern.html#top
replace
gmic shape_fern ,
by
gmic shape_fern


https://gmic.eu/reference/shape_gear.html#top
replace
gmic shape_gear ,
by
gmic shape_gear



https://gmic.eu/reference/shape_heart.html#top
replace
gmic shape_heart ,
by
gmic shape_heart


https://gmic.eu/reference/shape_polygon.html#top
Linux
???
Windows
gmic side=3 repeat 6 shape_polygon 256,$side side+=1 done


https://gmic.eu/reference/shape_snowflake.html#top
Linux
???
Windows
gmic recursion=1 repeat 5 shape_snowflake 256,$recursion recursion+=1 done
Edit rendering


https://gmic.eu/reference/shape_star.html#top
Linux
???
Windows
gmic branches=3 repeat 9 shape_star 256,$branches branches+=1 done
Edit rendering


https://gmic.eu/reference/shared.html#top
Linux
???
Windows
gmic image.jpg ind=1 repeat 2 shared 25%,75%,0,$ind mirror[-1] x remove[-1] ind+=1 done
Edit rendering


@David_Tschumperle:
The Technical Reference derives almost (maybe entirely?) from gmic/src/gmic_stdlib.gmic in the gmic repository, no? Am I correct in that the avenue toward addressing @samj 's observations would be edits to that file? But it is not clear to me the best way to implement changes that would be kinder to Windows11. The build environment is there, but I haven’t familiarized myself with it (perhaps I should).

Well yes, but TBH I didn’t understand what is really the request here from @samj .
I’d like some details, what should we do exactly?

@David_Tschumperle
@grosgood

Bonjour,

I simply note that the examples of the command lines are to be corrected or simply does not work in the HTML or PDF documentation.
There are problems under Linux and Windows.
I do not know how to correct these errors and I started a list of HTML pages where they are indicated.
I think it would be interesting to correct this documentation.

Je constate simplement que dans la documentation HTML ou PDF les exemples des lignes de commande sont Ă  corriger ou ne fonctionne tout simplement pas.
Il y a des problĂšmes sous Linux et Windows.
Je ne sais pas corriger ces erreurs et j’ai commencĂ© une liste de pages HTML oĂč elles sont indiquĂ©es.
Je crois qu’il serait intĂ©ressant d’avoir une documentation corrigĂ©e.

Merci :o)

Well, that’s probably because the example shown include “reserved” characters used also by the shell you use to run these commands.
But as these characters are different from one shell to another, I can’t give as many examples as there are existing shells.

Keep in mind that these special characters have to be “escaped” when invoking the command from a terminal. Also of course, all commands involving an argument such as image.jpg must replace this filename by a valid image name.

@David_Tschumperle

Je souhaite simplement que les exemples fournis fonctionnent et/ou soient corrects.
Voici un cas dans un terminal Linux adapté de la page

Je souhaite aussi avoir des exemples fonctionnant correctement selon les O.S. utilisés

Coping with the local shell is a perennial issue. It processes whatever is typed at the shell prompt before G’MIC even sees the command line string. Tutorial Land has a Custom Cheat which attempts to address this issue. Since shell prepossessing is a source of frustration for many a beginning script writer, I am thinking of moving some form of this cautionary way up front: to Start Here. Since the Technical Reference links to this page, its readers can benefit from such an early warning — so long as they follow the link.

Possibly, before offering such a link, the Technical Reference should have a terse warning of its own. Something to the effect of:

  • Be advised that the examples in this Reference are subject to shell preprocessing; successfully executing many examples calls for being familiar with your shell’s special characters and escaping them accordingly.
  • Alternatively, consider writing a small Custom Command to encapsulate the example. This bypasses most shell interaction. The tutorial outlines the basic approach.

Perhaps this is too verbose for the Technical Reference. But something like this could live in the more verbose tutorial guide, and the Reference can link to it.

1 Like

The examples are correct, when they are copy-pasted into a .gmic command file :

foo : 
image.jpg (1,2,3;4,5,6;7,8,9) (255^128^64) 400,400,1,3,'(x>w/2?x:y)*c'

will work as expected.
These examples are examples of use of the G’MIC language, not examples of shell commands.
There’s no point in giving examples of command lines running in a terminal if you don’t say which terminal it is (there are dozens of different terminals, each with its own specific features).
For a reference documentation, it is just not possible to give example that are working with all possible terminals. It’s not a question of ‘it should be working’, or not. It is just not possible to have this.

2 Likes

@David_Tschumperle

Je comprends bien ce point de vue et dans ce cas il serait bien de mettre votre commentaire comme avertissement dans la page:

Merci :o)

PrĂ©cision : Ajouter aussi ce commentaire au paragraphe ‘Usage’ de la page:

Merci :o)

1 Like

Of the proposed pages, I think Usage provides the best entry point, as it precedes a link to the tutorial page.

I propose the following language, approximately in the location of the red caret:

The examples accompanying The List of Commands illustrate the use of the G’MIC language and are written as they would appear in a custom command. While some examples may work if entered directly at a shell prompt, there is no guarantee. No attempt has been made to escape special characters in these examples, which many shells reserve
 _

The “Start Here” page, which one lands upon by following the Tutorial link, will be so modified to explicitly present a template for a “finger exercise”. This template is drawn directly from what @David_Tschumperle illustrated with custom command foo in Post 129 and the accompanying advice would suggest that a “finger exercise” is the easiest way to bypass most shell peculiarities. When the beginner lights upon a Technical Reference command description, they would be guided in how to turn that example into a finger exercise.

I’ll set about to do this at the next Tutorial upgrade, probably just after the Ides of June.

1 Like

I’ve added your suggestion here :

Thanks @grosgood !

1 Like

Thank you @grosgood for making these changes :o)


There are also layout problems with the very long command lines on the PDF document.
I don’t know if it can be easily corrected.


There are also problems where examples do not work in a Windows terminal and/or Bash Linux terminal:
add

gmic image.jpg repeat 9 { +rotate[0] {$>*36},1,0,50%,50% } add div 10

This modification works on the Windows terminal and on Bash Linux

gmic image.jpg ind=0 repeat 9 +rotate[0] {\$ind*36},1,0,50%,50% ind+=1 done add div 10

Merci :o)

Ah me. With my suggestion, I have induced @David_Tschumperle to open a can of worms:

this ‘List of Commands’ illustrate the use of the G’MIC language and are written as they would appear in a custom command.

Except, with $ gmic preceding most of the examples, there is the decided indication of a command line being in use, and not the interior of a custom command. So much for consistency in aims


Suggesting to adjust nine hundred or so commands is just my quaint little way of celebrating the 79th anniversary of the Invasion of Normandy, which is today, and marking one of the largest logistic exercises taken up in modern times. So, patching 900 or so commands? Pfft! Nothing compared to other kerfuffles that have taken place in and around Caen.

I think I shall be experimenting with some Emacs macros tonight, some of which have turned similar format automation tricks for me in times past, including line wraps for A4 paper. And yes, gmic_stdlib.gmic also underlies the -help command entries, as well as the Technical Reference, so a bit of care is in order. Might offer up trial patches along these lines this coming weekend. Cheers!

1 Like

Hi,
sadly neither works for me
 on zsh.

Had to write it like this :
gmic sp , repeat 9 +rotate\[0\] "{$>*36},1,0,50%,50%" done add div 10

or like this :face_with_spiral_eyes: :
gmic sp , repeat 9 +rotate\[0\] \{$\>\*36\},1,0,50%,50% done add div 10

I guess a solution regarding syntax difference per shell is to write a Python script that would address those limitations when it comes, and have user select shell example choices. I could do a bit of that via Python and regex as now I know how to use Python to automate G’MIC coding. But, I think that’s just way too much regardless. Maybe later I could help on that, but between G’MIC things and other things I like doing, consider me out on that.

Wouldn’t it be easier to write a script that generates .gmic files like @David_Tschumperle’s example ? And add it as download?

One simple trick for Linux :
If your G’MIC command line does not use the single quote character ', then using command run is a good way to execute commands :

$ gmic run 'sp , repeat 9 +rotate[0] {$>*36},1,0,50%,50% done add div 10'
1 Like

Oh that’s nice indeed. Just add v 1inside the quotes to see what’ s happening:

gmic run 'v 1 sp , repeat 9 +rotate[0] {$>*36},1,0,50%,50% done add div 10'

2 Likes