fsleyes_widgets.utils.textbitmap

This module provides a single function, textBitmap(), which renders some text off-screen using matplotlib, and returns it as an RGBA bitmap.

fsleyes_widgets.utils.textbitmap.POINT_SIZE = 0.013888888888888888

Size of one point in inches at 72 dpi. Font sizes are specified in points at 72 dpi - this value is used to convert from font size to inches (and on to pixels).

fsleyes_widgets.utils.textbitmap.textBitmap(text, width=None, height=None, fontSize=None, fgColour=None, bgColour=None, alpha=1.0, fontFamily=None, halign=None, dpi=96)[source]

Draw some text using matplotlib.

The rendered text is returned as a RGBA bitmap within a numpy.uint8 array of size \(h \times w \times 4\), with the top-left pixel located at index [0, 0, :].

At least one of the fontSize or the height arguments need to be specified - if one of these is provided, the other size options will be inferred, although the inference procedure does not support multi-line text.

Parameters:
  • text – Text to render.

  • width – Width in pixels.

  • height – Height in pixels.

  • fontSize – Font size in points.

  • fgColour – Foreground (text) colour - can be any colour specification that is accepted by matplotlib.

  • bgColour – Background colour - can be any colour specification that is accepted by matplotlib..

  • alpha – Text transparency, in the range [0.0 - 1.0].

  • fontFamily – Font family, e.g. 'monospace' or 'sans-serif', defaults to matplotlib default.

  • dpi – Dots per inch, defaults to 96.

  • halign – Horizontal alignment - one of 'centre' (default), 'center', 'left' or right'.

Returns:

numpy.uint8 array of size \(h \times w \times 4\)