Can G'MIC batch-process multiple layers then merge them?


I’m trying to do something like this:

Open an image.
Duplicate the image/layer.
Run Black & White > Pencil Portrait filter on the duplicate layer.
Then set the opacity on the original layer to 50%
Merge both layers.

Then do the same to 5,500 images
I know how to use the command line (in windows and linux environments) to set multiple filters to run a batch of single images. But I don’t know how to do the layering that I described above. Does G’Mic offer this functionality?

(Pat David) #2

Yes, G’MIC can do this, but I’ll have to defer to an expert for the actual syntax…

(David Tschumperlé) #3

Maybe something like this, with the command line tool gmic:

  • For a single image, and for 8bits/channels .png files:
$ gmic input.png --gimp_pencil_portraitbw 30,120,1,0.5,144,79,21,0 -blend alpha,0.5 -o result.png

(change parameters according to your needs).

  • For multiple images :

$ gmic -apply_files \*.png,\"–gimp_pencil_portraitbw 30,120,1,0.5,144,79,21,0 -blend alpha,0.5\",0,-1,1,output.png


The -blend alpha is a function I wasn’t aware of. I’m going to make a thorough study of it. This was far simpler (in execution) than I had anticipated.

One final question, could I apply an additional layer (of the original picture) in mode Overlay, over the 50% opacity layer?

(David Tschumperlé) #5

Something like this maybe (with a 100% opacity for the overlay mode) ?

gmic input.png --gimp_pencil_portraitbw 30,120,1,0.5,144,79,21,0 -blend[-1] [-2],alpha,0.5 -rv -blend overlay -o output.png


Wow David, that’s amazing!

I’ve been researching G’MIC’s capabilities and I’m starting to realize just how MUCH it can do. I’m diving into some rather advanced automated layering options to make some videos really POP.

Please tell me if I’m understanding the command(s) you gave me correctly:
gmic input.png --gimp_pencil_portraitbw 30,120,1,0.5,144,79,21,0 -blend[-1] [-2],alpha,0.5 -rv -blend overlay -o output.png

The – means keep the original picture and work off of a copy. Then it applied the filter specs for Pencil Portrait. Here’s where I get a little lost, you assign the original picture to -1 and the copy to -2 and then blend the opacity by 50%. Then you somehow use a reverse command to apply another layer (I’m not sure where it’s coming from) and apply it to overlay with 100% opacity, and then somehow it merges it all (but I’m not seeing a merge or flatten command, does it do this by default?).

I’m researching here:
& here:

But it’s coming slow. I’m very grateful for the command(s) but now I need to understand them. Otherwise, I’ll not understand how to do this myself. Any advice you, or others, have would be appreciated.

(David Tschumperlé) #7

Let’s do it step by step:

gmic input.png

Now you have a single image in your list, numbered [0] (or also [-1]).

–gimp_pencil_portraitbw 30,120,1,0.5,144,79,21,0

Now you have two images [-2] (original image) and [-1] (result of the pencil portrait filter).

-blend[-1] [-2],alpha,0.5

Using this particular form of the -blend command modifies only the image [-1]. Here, it replaces your second image [1] (or also [-1]) by the blending between the original image and the pencil portrait image.
You still have two images in your list at this point, as image [0] (aka [-2]) has not been modified here.


(equivalent to -reverse) will change the order of your images. Now image [0](aka [-2]) is the blending previously computed, and image [1] (aka [-1]) is the original image, which has been untouched since the beginning of the process.

-blend overlay

Here, I use the second form of the command -blend, which blend selected images together. Here the selection is not written, so it assumes it works on the whole set of image, i.e. command selection is [-2,-1]. We could have written -blend[-2,-1] overlay to get the same result. With this form of the -blend command, it is assumed the first image is the background layer, and the second image is the foreground layer, so for blending in overlay mode here, that’s precisely the order I’d like to have (original image as the top layer).

Not sure it helps a lot, I’m so used to write G’MIC command lines that I often forget this is probably not trivial to understand, sorry about that :slight_smile:


That made perfect sense to me, thank you for the clear and detailed explanation. You have helped me considerably. Thank you for time you’ve taken. :smile: