Custom font on G'MIC

How would I create a image containing a user defined font?

I want to recreate the background of cars in this image:

@Reptorian Since it is you who are asking,
I presume you are after a clever script,
and not a fully manual approach :frowning: ?

Have fun,
Claes in Lund, Sweden

Yes, I am after a clever script.

It’s currently not possible to change the default font when displaying text in G’MIC, with command text. But this could be considered as an extension for the next version.
In CImg, there is indeed already an option to allows this, in method CImg<T>::draw_text().

The question is : what is the best way for the user to specify the font? G’MIC has a very limited text drawing routine, so don’t expect complicated things like being able to specify .ttf vectorized fonts for the rendering.
In CImg, a font is given as a list of 256 (or 512) images, each being an image of a single character (encoded in 8 bits, so 256 letters + 256 optional masks associated).
This should be given as a list also in G’MIC (and not as a single image, e.g a volumetric image with characters stacked along the z-axis), because each character may have a different width (or height).

Maybe the best way I’m thinking about right now is to allow the command text to allows a syntax like:

text,_x[%|~],_y[%|~],_font_name,_opacity,_color1,...

where font_name is the name of a list-encoded variable that contains the font to be used
(e.g. stored before with something as store[0-255] font_name).

I need to think a bit more about that possibility.

1 Like

Having the possibility to use custom fonts will be available in the next version:

In G’MIC, a “font” is considered as a list of 256 images (or 512, with masks) in value range [0,255], that must be stored in a variable (using command store), as shown by the example below:

foo :
  # Create background image.
  900,300,1,3 plasma. 10,10 n. 0,128

  # Create custom font.
  l[] { fontchart s. yx,16 r2dx. 75% r[32] 30,100% rv +f 255 to_rgb[-256--1] rv store custom_font }

  # Draw text with custom font.
  t. "G'MIC Rocks!",0.5~,0.5~,custom_font,1,128,255,128

which gives:

1 Like