nider package

nider.core module

class nider.core.Font(path=None, size=18)[source]

Base class for text’s font

Parameters:
  • path (str) – path to the font used in the object.
  • size (int) – size of the font.
Raises:
class nider.core.Outline(width=2, color=None)[source]

Base class for text’s outline

Parameters:
  • width (int) – width of the stroke.
  • color (str) – string that represents outline color. Must be compatible with PIL.ImageColor color names.

Warning

Due to PIL limitations - core library used for drawing, nider doesn’t support ‘true’ outlineі. That is why high width outlines will look rather ugly and we don’t recommend usign outlines with width > 3.

nider.models module

class nider.models.Header(text, font=None, text_width=21, line_padding=6, color=None, outline=None, align='center')[source]

Class that represents a header used in images

Parameters:
  • text (str) – text used for the unit.
  • font (nider.core.Font) – font object that represents text’s font.
  • text_width (int) – units’s text width - number of characters in a line.
  • line_padding (int) – unit’s line padding - padding (in pixels) between the lines.
  • color (str) –

    string that represents a color. Must be compatible with PIL.ImageColor color names.

  • outline (nider.core.Outline) – outline object that represents text’s outline.
  • align ('left' or 'center' or 'right') – side with respect to which the text will be aligned.
Raises:
class nider.models.Paragraph(text, font=None, text_width=21, line_padding=6, color=None, outline=None, align='center')[source]

Class that represents a paragraph used in images

Parameters:
  • text (str) – text used for the unit.
  • font (nider.core.Font) – font object that represents text’s font.
  • text_width (int) – units’s text width - number of characters in a line.
  • line_padding (int) – unit’s line padding - padding (in pixels) between the lines.
  • color (str) –

    string that represents a color. Must be compatible with PIL.ImageColor color names.

  • outline (nider.core.Outline) – outline object that represents text’s outline.
  • align ('left' or 'center' or 'right') – side with respect to which the text will be aligned.
Raises:
class nider.models.Linkback(text, font=None, color=None, outline=None, align='right', bottom_padding=20)[source]

Class that represents a linkback used in images

Parameters:
  • text (str) – text used for the unit.
  • font (nider.core.Font) – font object that represents text’s font.
  • color (str) –

    string that represents a color. Must be compatible with PIL.ImageColor color names

  • outline (nider.core.Outline) – outline object that represents text’s outline.
  • align ('left' or 'center' or 'right') – side with respect to which the text will be aligned.
  • bottom_padding (int) – linkback’s bottom padding - padding (in pixels) between the bottom of the image and the linkback itself.
Raises:
class nider.models.Watermark(text, font, color=None, outline=None, cross=True, rotate_angle=None, opacity=0.25)[source]

Class that represents a watermark used in images

Parameters:
  • text (str) – text to use.
  • font (nider.core.Font) – font object that represents text’s font.
  • color (str) –

    string that represents a color. Must be compatible with PIL.ImageColor color names

  • outline (nider.core.Outline) – outline object that represents text’s outline.
  • cross (bool) – boolean flag that indicates whether watermark has to be drawn with a cross.
  • rotate_angle (int) – angle to which watermark’s text has to be rotated.
  • opacity (0 <= float <= 1) – opacity level of the watermark (applies to both the text and the cross).
Raises:

Note

Watermark tries to takes all available width of the image so providing font.size has no affect on the watermark.

class nider.models.Content(paragraph=None, header=None, linkback=None, watermark=None, padding=45)[source]

Class that aggregates different units into a sigle object

Parameters:
Raises:

nider.exceptions.ImageGeneratorException – if neither of paragraph, header or linkback is provided.

Note

padding is taken into account only if image is to get resized. If size allows content to fit freely, pre-calculated paddings will be used.

Note

Content has to consist at least of one unit: header, paragraph or linkback.

class nider.models.Image(content, fullpath, width=1080, height=1080, title=None, description=None)[source]

Base class for a text based image

Parameters:
  • content (nider.models.Content) – content object that has units to be rendered.
  • fullpath (str) – path where the image has to be saved.
  • width (int) – width of the image to be generated.
  • height (int) – height of the image to be generated.
  • title (str) – title of the image. Serves as metadata for latter rendering in html. May be used as alt text of the image. If no title is provided content.header.text will be set as the value.
  • description (str) – description of the image. Serves as metadata for latter rendering in html. May be used as description text of the image. If no description is provided content.paragraph.text will be set as the value.
Raises:
draw_on_bg(bgcolor=None)[source]

Draws preinitialized image and its attributes on a colored background

If bgcolor is set to None, random nider.colors.colormap.FLAT_UI_COLORS will be taken.

Parameters:bgcolor (str) –

string that represents a background color. Must be compatible with PIL.ImageColor color names

Raises:nider.exceptions.ImageSizeFixedWarning – if the image size has to be adjusted to the provided content’s size because the content takes too much space.
draw_on_image(image_path, image_enhancements=None, image_filters=None)[source]

Draws preinitialized image and its attributes on an image

Parameters:
  • image_path (str) – path of the image to draw on.
  • image_enhancements (itarable) – itarable of tuples, each containing a class from PIL.ImageEnhance that will be applied and factor - a floating point value controlling the enhancement. Check documentation of PIL.ImageEnhance for more info about availabe enhancements.
  • image_filters (itarable) –

    itarable of filters from PIL.ImageFilter that will be applied. Check documentation of PIL.ImageFilter for more info about availabe filters.

Raises:

FileNotFoundError – if image file at path image_path cannot be found.

draw_on_texture(texture_path=None)[source]

Draws preinitialized image and its attributes on a texture

If texture_path is set to None, random texture from nider/textures will be taken.

Parameters:

texture_path (str) – path of the texture to use.

Raises:
  • FileNotFoundError – if texture file at path texture_path cannot be found.
  • nider.exceptions.ImageSizeFixedWarning – if the image size has to be adjusted to the provided content’s size because the content takes too much space.
class nider.models.FacebookSquarePost(*args, **kwargs)[source]

Alias of nider.models.Image with width=470 and height=470

class nider.models.FacebookLandscapePost(*args, **kwargs)[source]

Alias of nider.models.Image with width=1024 and height=512

nider.models.TwitterPost

alias of nider.models.FacebookLandscapePost

class nider.models.TwitterLargeCard(*args, **kwargs)[source]

Alias of nider.models.Image with width=506 and height=506

class nider.models.InstagramSquarePost(*args, **kwargs)[source]

Alias of nider.models.Image with width=1080 and height=1080

class nider.models.InstagramPortraitPost(*args, **kwargs)[source]

Alias of nider.models.Image with width=1080 and height=1350

class nider.models.InstagramLandscapePost(*args, **kwargs)[source]

Alias of nider.models.Image with width=1080 and height=566

nider.exceptions module

exception nider.exceptions.AutoGeneratedUnitColorUsedWarning(unit, color_used)[source]

Warning raised when auto generated unit color was used

exception nider.exceptions.AutoGeneratedUnitOutlinecolorUsedWarning(unit, color_used)[source]

Warning raised when auto generated unit’s outline color was used

exception nider.exceptions.DefaultFontWarning[source]

Warning raised when default font was used

exception nider.exceptions.FontNotFoundException(fontpath_provided)[source]

Exception raised when font cannot be found

exception nider.exceptions.FontNotFoundWarning(fontpath_provided)[source]

Warning raised when font cannot be found

exception nider.exceptions.ImageGeneratorException[source]

Base class for exceptions raised by nider

exception nider.exceptions.ImageGeneratorWarning[source]

Base class for warnings raised by nider

exception nider.exceptions.ImageSizeFixedWarning[source]

Warning raised when the size of the image has to be adjusted to the provided content’s size because the content takes much space

exception nider.exceptions.InvalidAlignException(align_provided, available_aligns=None)[source]

Exception raised when align is not supported by nider