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: nider.exceptions.DefaultFontWarning
– ifpath
isNone
.nider.exceptions.FontNotFoundWarning
– ifpath
does not exist.
-
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: nider.exceptions.InvalidAlignException
– if ``align` is not supported by nider.AttributeError
– iftext_width
< 0.nider.exceptions.DefaultFontWarning
– iffont.path
isNone
.nider.exceptions.FontNotFoundWarning
– iffont.path
does not exist.
-
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: nider.exceptions.InvalidAlignException
– if ``align` is not supported by nider.AttributeError
– iftext_width
< 0.nider.exceptions.DefaultFontWarning
– iffont.path
isNone
.nider.exceptions.FontNotFoundWarning
– iffont.path
does not exist.
-
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: nider.exceptions.InvalidAlignException
– ifalign
is not supported by nider.nider.exceptions.DefaultFontWarning
– iffont.path
isNone
.nider.exceptions.FontNotFoundWarning
– iffont.path
does not exist.
-
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: nider.exceptions.ImageGeneratorException
– iffont
is the default font.nider.exceptions.DefaultFontWarning
– iffont.path
isNone
.nider.exceptions.FontNotFoundWarning
– iffont.path
does not exist.
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: - paragraph (nider.models.Paragraph) – paragraph used for in the content.
- header (nider.models.Header) – header used for in the content.
- linkback (nider.models.Linkback) – linkback used for in the content.
- watermark (nider.models.Watermark) – watermark used for in the content.
- padding (int) – content’s padding - padding (in pixels) between the units.
Raises: nider.exceptions.ImageGeneratorException
– if neither ofparagraph
,header
orlinkback
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: nider.exceptions.ImageGeneratorException
– if the current user doesn’t have sufficient permissions to create the file at passedfullpath
.AttributeError
– if width <= 0 or height <= 0.
-
draw_on_bg
(bgcolor=None)[source]¶ Draws preinitialized image and its attributes on a colored background
If
bgcolor
is set toNone
, randomnider.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 ofPIL.ImageEnhance
for more info about availabe enhancements. - image_filters (itarable) –
itarable of filters from
PIL.ImageFilter
that will be applied. Check documentation ofPIL.ImageFilter
for more info about availabe filters.
Raises: FileNotFoundError
– if image file at pathimage_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 toNone
, random texture fromnider/textures
will be taken.Parameters: texture_path (str) – path of the texture to use.
Raises: FileNotFoundError
– if texture file at pathtexture_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
withwidth=470
andheight=470
-
class
nider.models.
FacebookLandscapePost
(*args, **kwargs)[source]¶ Alias of
nider.models.Image
withwidth=1024
andheight=512
-
nider.models.
TwitterPost
¶ alias of
FacebookLandscapePost
-
class
nider.models.
TwitterLargeCard
(*args, **kwargs)[source]¶ Alias of
nider.models.Image
withwidth=506
andheight=506
-
class
nider.models.
InstagramSquarePost
(*args, **kwargs)[source]¶ Alias of
nider.models.Image
withwidth=1080
andheight=1080
-
class
nider.models.
InstagramPortraitPost
(*args, **kwargs)[source]¶ Alias of
nider.models.Image
withwidth=1080
andheight=1350
-
class
nider.models.
InstagramLandscapePost
(*args, **kwargs)[source]¶ Alias of
nider.models.Image
withwidth=1080
andheight=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.
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