The Big Bad G'MIC Thread of Silly Questions

Perfect for obfuscation in fact. There’s plenty of other obfuscation techniques for G’MIC if one wants to have fun doing that.

Sure, like this one:

foo :
  base642img "MiB1aW50OCBsaXR0bGVfZW5kaWFuCjUyIDEgMSAxICM1OAp4nEvOz1WwUtBOVYjJi8lTyixRL1YoKEotKalUKE/NyVHIT0orLU5OLElNUUjOT0lVVAIpAwDPZhIFMSA2NSAxIDEgIzY3Cnicc/eNYtBQT87PVbBS0E5ViInJAyKlzBL1YoWCotSSkkqF8tScHIX8pLTS4uTEktQUheT8lFRFJYhCdU0GAKP0FQI=" m {/{t}} rm.
  com
1 Like

Just to add madness to the nightmare? :laughing:

1 Like

Experiment in terror : Having fun adding filters to the list :technologist:


Canvas and bump as post-process.

2 Likes

Hi all,
what did i do wrong here?
I used parse_cli to check one of my commands (because i’m curious) and for some reason there is some info about another user?

$ gmic  parse_cli ascii,pr_dcm8
[gmic]./ Start G'MIC interpreter (v.3.3.3).
[gmic]./ Parse '#@cli' command(s) 'pr_dcm8' and output in 'ascii' mode.
  1.1. User Karo's GIMP/gui Custom functions
       -------------------------------------

  pr_dcm8:
      _strength,_interpolation

    Quickly pixelize an image while keeping dimensions

    Default value: 'strength=50', 'interpolation=1'
    pr_dcm8 80
[gmic]./ End G'MIC interpreter.

You are right, that is a bug.
Fixed with:

Do $ gmic update to get the fix.

Oh thanks for the fix. I thought i had to sort my file a little.

I have another question :
In my effect, when some conditions are met, like in the capture below, autocrop sends my image into oblivion. That’s because the settings before the crop output a 100% transparent image and autocrop just crops it to 0x0 (autocrop is only called when angle is higher than 0).
I’m looking for a way to avoid this, i’d rather get and empty image or black image than an error. Any idea? How can i detect that there is something in the image before using autocrop?

You can actually compute the autocrop and check if the resulting image is not empty:

# Assuming [-1] is an image of some kind.
+autocrop. 0 
if !w # Empty image -> all image has been cropped
  rm.  # Keep the original image
else
  rm.. # Keep the cropped image
fi
1 Like

Thanks, it works fine. Actually, that was easier than i thought :flushed:

btw, how does if !w know which image to check? Is it always [-1] by default?

Yes, by default, a math expression outside a fill use the latest image as the “reference image”.
That is very convenient.

1 Like

Hi,
i’m trying to draw circles in random positions but i don’t want them to be clipped if the center is too close to the image’s edge, so i want to shift the circle’s center back into the image by at least it’s radius “amount”.
I have this so far and it seems to work, but i’m not sure if it’s the right way to do it since my brain can’t calculate all the possibilities:

# Note : $1,$2,$3,$4 = 0 for this exemple.
# Used to set L,R,T,B margins, here = none.
# Everything's in % (at least i want it to be)
ML=$1   
MR:=100-$2
MT=$3
MB:=100-$4
 repeat $7 { # 100x 
    CR:=u(5) CX:=u($ML,$MR) CY:=u($MT,$MB)
    # had to *1.5 for some reason? Else circles go out of bounds
    #Makes me think i'm doing it wrong...
    if $CX-$CR<=$CR CX:=$CR*1.5 fi  
    if $CX+$CR>=100-$CR CX:=100-$CR*1.5 fi
    if $CY-$CR<=$CR CY:=$CR*1.5 fi
    if $CY+$CR>=100-$CR CY:=100-$CR*1.5 fi
    circle $CX%,$CY%,$CR%,{u},0xFFFFFFFF,255
  }

Do anyone know a sure way to do it ? Thanks.

EDIT : This seems to work fine i guess :

 repeat $7 {
    CR:=u(5) 
    CX:=u($ML+$CR*1.5,$MR-$CR*1.5) 
    CY:=u($MT+$CR*1.5,$MB-$CR*1.5)
    circle $CX%,$CY%,$CR%,{u},0xFFFFFFFF,255
  }

PS : Is there any way to find out what can be set as outline patterns?

I think @afre asked that question before, and David gave a response.

Probably this?

Yeah, I think it was that. There’s another way of coding this, but it involves the math parser, and I don’t think I can help you much with that other than to tell you to try to experiment with it and then learn it. It’s like learning another programming language.

Yes, one day i’ll have to learn how to use it, but i’m already struggling with basic stuff so i guess it won’t be anytime soon.
I guess i’m just prototyping for now?

Anyway, i got to do what i wanted to do, that is “seamless random patterns”.
Now i have to add some colors and learn to draw different shapes and objects… That’s the hardest part i guess.
And make it less chaotic, huh.

EDIT: playing with margins gave me some fun results :

2 Likes

What would be the correct way to write this little color randomizer (randomly choosing from 8 user defined colors):

rcol:
col:=floor(u(1,8))
if $col==1 C=$1,$2,$3
  elif $col==2 C=$4,$5,$6
  elif $col==3 C=$7,$8,$9
  elif $col==4 C=$10,$11,$12
  elif $col==5 C=$13,$14,$15
  elif $col==6 C=$16,$17,$18
  elif $col==7 C=$19,$20,$21
else C=$22,$24,$24 fi
u {$C}
rectangle {20%,80%,20%,80%,{u(.5,1)},0xFFFFFFFF,${"-rcol ${11--1}"} }

I just don’t want to copy paste the whole rcol code before every rectangle, polygon or circle call…
For now all i get is an error:

replace this by u $C, the evaluation of $C is incorrect (3 values separated by commas means nothing for the math expression).

1 Like

Thanks, it works now :slight_smile:

Is there any way to write a function inside a custom command? I’m not sure i want to keep rcol as a standalone command. This thing just eats 24 values to randomly select one RGB color among 8. Not really useful outside of it’s main command.

Yes, you can define a “temporary” command inside a custom command, with command command, then uncommand it when you’re done, with command uncommand.
In your case anyway, I would use the math evaluator to have a shorten version of rcol that you can store in a string and use it wherever you want:
Something like :

foo :
  rcol="arg0(int(u(8))%8,[${1-3}],[${4-6}],[${7-9}],[${10-12}],[${13-15}],[${16-18}],[${19-21}],[${22-24}])"
  rectangle 20%,80%,60%,90%,{u(.5,1)},0xFFFFFFFF,{$rcol}
  rectangle 10%,50%,40%,70%,{u(.5,1)},0xFFFFFFFF,{$rcol}

My solution to this problem is more akin to using a image. Something like these:

foo:
(${1-24}) steps:=24/3
rectangle[-2]  20%,80%,60%,90%,{u(.5,1)},0xFFFFFFFF,{crop(#-1,int(u(0,$steps,1,0)),0,0,0,3,1,1,1,0))}

or

foo:
(${1-24}) permute cyzx
rectangle[-2] 20%,80%,60%,90%,{u(.5,1)},0xFFFFFFFF,{I[#-1,int(u(0,w#-1,1,0))]}

I do wish we had something like this syntax (which would enable a easy to read one-liner):

$(5,13,15)=$5,$13,$15 # Arbitrarily select arguments based on what is inside ()