Release of G'MIC 3.0

Now I’m probably pushing my luck with one more question, but I can’t find a way to get the output of files (i.e. status) directly into an image with quoting intact, without first going via arg2var (or at least “converting” them individually to variables with $=var). Is that correct? The goal being to preserve filenames which contain spaces and/or commas.

Interesting question! It’s definitely not easy, as space and comma characters have a special meaning in the G’MIC language, and string substitution may occur here and there.
After experimenting a bit, I found this ‘minimal’ way (so far) to handle this case. Beware, it’s very tricky!!

# Tricky way of getting list of filenames containing spaces or commas!
foo :
  files *

  # Convert status into an image where each row = one filename.
  m "$0_f2i: $""=arg repeat $""# ({'${arg{1+$>}}'}) done a y" $0_f2i[] ${} um $0_f2i

  # Print filenames.
  repeat h e {`crop(0,$>,w,1)`} done

EDIT: Fix code snippet.

Multiple labels in selection is now handled correctly (was not the case before I guess).
Anyway, in that particular case of add[first,second] (without arguments), you need to know how the indices of first and last are sorted, to guess in which of the two image the result is merged.
In that case, I’d rather suggest to add the version of add that takes one argument:

add[first] [second] rm[second]

so this works whatever the relative order of [first] and [second] is.

This foo snippet is probably worth begin converted into a files2img function in the convenience functions of the stdlib!

1 Like

Here it is, now you should be able to use files2img as a helper.

https://github.com/dtschump/gmic/commit/a0fcd1546086bd37c56b5defd014afe7f31fe687

should be available in the update file in a few minutes.

1 Like

I’m quite glad to see I wasn’t just being stupid… as mentioned in the past, the one thing I struggle with in g’mic is string handling. It generally takes me more time to write code manipulating strings than to write a fairly complex image pipeline. For some reason, I find it difficult to predict the behaviour.

I’d say this is normal, even intended :slight_smile:
G’MIC is basically not a string processing language, even if, with some tricks and motivation, we can use it for this purpose!

1 Like

Yes true, if we push outside the intended uses then we can expect some hardship!
Anyway, I believe this is the end of my questions for a little while now :smiley:

1 Like

Here is the code of the finished command files2img:

#@cli files2img : _mode,path
#@cli : Insert a new image where each row corresponds to one filename returned by command ''files''.
#@cli : Useful to manage list of filenames containing characters that have a special meaning in the G'MIC language,
# such as spaces or commas.
+files2img :
  if ['$$_$0_f2i']==0 m "_$0_f2i: $""=arg repeat $""# ({'${arg{1+$>}}'}) done a y" fi
  files $"*" l[] _$0_f2i[] ${} if !$! 0 fi endl

Definitely tricky :slight_smile: But that’s what I like sometimes with G’MIC, something very tricky can become a new command that is simple to use.

Hah, so ugly that it’s beautiful

1 Like

That said, -gmd2html and other translators in that vein furnish a good many interesting examples of G’MIC string processing. Not bad product for something that is " basically not a string processing language."

Yes, that is cool, but really, I would not advise to do this kind of thing in G’MIC, even to my worst enemy. I did it to push my limits in the use of the interpreter, but it was not necessarily a pleasure! :slight_smile:

1 Like

This is why I had to learn Python. I find it very difficult to work with string in G’MIC even though I can do it for image-processing task, but for tasks that are exclusively about string, I will just boot up Thonny and code in Python. Maybe calling Python code from G’MIC would be good here.

Methinks -exec is your friend. The “command” argument to -exec is your Python script file, marked to be executable. Set -exec to verbose and capture your Python script’s standard output stream; -exec returns such as status. Ditto standard error (and only standard error should verbose not be set). Works fine in Linux bash shells - never tried the equivalent with Windows command shells or PowerShell.

1 Like

Made a lot of tutorial writing possible, though. You got a return on your investment.

1 Like

Merci @grosgood

Full screen visualization of images works properly using the Windows 64 PowerShell ISE terminal : PowerShell_ISE.exe

Malfunction with the PowerShell terminal (mouse cursor).

Exemple :

./gmic cursor 0 repeat 20 sp k. r 1920,1080 w. 100%,100%,0,1 cursor 0 wait done

Please don’t stop asking for things, because each time you do so I end up adding some new features in G’MIC (da_pop(), da_back(), files2img). As I plan to release major version 3.0.0 soon, I’d be happy not to have important stuffs to add after the release :slight_smile:

Can it do some sort of wildcard parsing now for files , with files2img ? Or is it only from a text file?

Oh! Boo-hoo, Boo-hoo! @garagecoder doesn’t want to ask questions any more! Doesn’t he know that questions are more fun than answers?

Oh well, since @garagecoder has gone radio-silent, here’s my bid for 3.0.0. I’m sure this has been asked before, but, hey! This is the big one!

Extend names to math expressions.

nameit :
   (250,114^148,159^254,207)
   r. 32,100%,100%,100%,5
   name. pinkblue
      (204,78^0,154^0,6)
   r. 32,100%,100%,100%,5
   name. rustgreen
   # silly, but works
   foo={crop(#0,0,0,0,0,w/2,1,1,1)+crop(#1,w/2,0,0,0,w/2,1,1,1)}
   echo $foo
   # same kind of silly, and naming things does not work
   bar={crop(#pinkblue,0,0,0,0,w/2,1,1,1)+crop(#rustgreen,w/2,0,0,0,w/2,1,1,1)}
   echo $bar

yields:

 $ gmic nameit.gmic nameit
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'nameit.gmic' (1 new, total: 4465).
[gmic]-2./nameit/ 388.460205078125,380.99205017089844,373.16477966308594,365.03118896484375,356.64401245117188,348.05606079101562,339.32006072998047,330.48880767822266,321.61504364013672,312.75157165527344,303.95112609863281,295.26649475097656,286.75042724609375,278.45571136474609,270.43510437011719,262.74136352539062
[gmic] *** Error in ./nameit/ *** Item substitution '{crop(#pinkblue,0,0,0,0,w/2,1,1(...)ustgreen,w/2,0,0,0,w/2,1,1,1)}': Unrecognized item 'pinkblue' in expression 'crop(#pinkblue,0,0,0,0,w/2,1,1,1)'.

Oh, shoot. So — names in math expressions, please?

I believe this will work:

 bar={crop(#$pinkblue,0,0,0,0,w/2,1,1,1)+crop(#$rustgreen,w/2,0,0,0,w/2,1,1,1)}