geepillow.blocks#

Blocks module.

Blocks are the basic units to use in strips and grids, and do not overlay with each other.

There are 2 types:

  • ImageBlock: contains an image inside.

  • TextBlock: contains text inside.

If the user needs to add text overlaying the image, can do it using the PIL library.

Attributes#

Classes#

Block

Basic Block.

ImageBlock

Image Block for PIL images.

TextBlock

TextBlock.

Module Contents#

class geepillow.blocks.Block(size=DEFAULT_SIZE, background_color='white', background_opacity=1, mode=DEFAULT_MODE)[source]#

Basic Block.

The background will always be an image that will cover the whole block. Then the inner element will be painted on top of the background image.

This object is mutable. All properties, except “element” can be modified.

Parameters:
  • size (tuple) – size of the block in pixels.

  • background_color (str | geepillow.colors.Color) – color of the background.

  • background_opacity (float) – opacity of the background.

  • mode (str) – mode of the background image.

set_size(size)[source]#

Set or modify the size of the block.

Parameters:

size (tuple)

DEFAULT_SIZE = (500, 500)[source]#
_background_color[source]#
_size = (500, 500)[source]#
property background_color[source]#

Background color.

property background_hex[source]#

Background hex color.

property background_image[source]#

The background image.

background_opacity = 1[source]#
property height[source]#

Height of the block.

property image[source]#

For basic blocks the image is the background image.

mode = 'RGBA'[source]#
property size[source]#

Size of the block.

property width[source]#

Width of the block.

class geepillow.blocks.ImageBlock(image, position='center-center', fit_block=True, keep_proportion=True, size=None, background_color='white', background_opacity=1, mode=DEFAULT_MODE)[source]#

Bases: Block

Image Block for PIL images.

Parameters:
  • image (PIL.Image.Image) – the image.

  • position (tuple | PositionType) – position of the image inside the block.

  • fit_block (bool) – if True the element’s boundaries will never exceed the block.

  • keep_proportion (bool) – keep proportion (ratio) of the image.

  • size (tuple | None) – size of the block (not the image). Defaults to the image size.

  • background_color (str | geepillow.colors.Color) – color of the background.

  • background_opacity (float) – opacity of the background.

  • mode (str) – mode of the background image.

classmethod from_file(filename, **kwargs)[source]#

Create an ImageBlock from a file.

Parameters:

filename (str | pathlib.Path)

_image[source]#
property element: PIL.Image.Image[source]#

Element.

The original image will be modified according to size of the block and properties fit_block and keep_proportion.

Return type:

PIL.Image.Image

fit_block = True[source]#
property image: PIL.Image[source]#

Image of the block.

Return type:

PIL.Image

keep_proportion = True[source]#
position = 'center-center'[source]#
property xy[source]#

Coordinates (X,Y) of the top-left corner of the inner image.

class geepillow.blocks.TextBlock(text, position='center-center', font=DEFAULT_FONT, text_color='black', text_opacity=1, background_color='white', background_opacity=1, fit_block=False, keep_proportion=True, size=None, mode=DEFAULT_MODE)[source]#

Bases: ImageBlock

TextBlock.

Parameters:
  • text (str) – text to display.

  • position (tuple | PositionType) – position of the text inside the block.

  • font (FontType) – font to use. The size the font is included in this parameter.

  • text_color (str | geepillow.colors.Color) – color of the text.

  • text_opacity (float | int) – opacity of the text.

  • background_color (str | geepillow.colors.Color) – color of the background.

  • background_opacity (float | int) – opacity of the background.

  • fit_block (bool) – if True the element’

  • keep_proportion (bool) – keep proportion (ratio) of the image.

  • size (tuple | None) – size of the block (not the image). Defaults to the image size.

  • mode (str) – mode of the background image.

create_text_image()[source]#

Create a text image.

Return type:

PIL.Image.Image

_background_color[source]#
_font[source]#
_text[source]#
_text_color[source]#
background_opacity = 1[source]#
property font[source]#

Font to use.

mode = 'RGBA'[source]#
property text: str[source]#

Text to display.

Return type:

str

property text_color: geepillow.colors.Color[source]#

Text color.

Return type:

geepillow.colors.Color

property text_height: int[source]#

Calculate height for a multiline text.

Return type:

int

text_opacity = 1[source]#
property text_width: int[source]#

Calculate width for a multiline text.

Return type:

int

geepillow.blocks.DEFAULT_FONT[source]#
geepillow.blocks.DEFAULT_MODE = 'RGBA'[source]#
geepillow.blocks.FontType[source]#
geepillow.blocks.PositionType[source]#