scistag.imagestag.html_renderer.HtmlRenderer

class HtmlRenderer[source]

Bases: object

The HtmlRenderer allows the conversion from HTML code to an image for example to create the thumbnail of a web page or to integrate HTML elements into a slide.

Important: Needs te optional imgkit module and wkhtmltopdf (https://wkhtmltopdf.org/)

Initializer

Methods

dummy_image

Returns a dummy image if not data is available

render

Renders the HTML code to an image

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

image

The rendered web page

static _generate_html(bg_color, options)[source]

Generates the html data

Parameters
  • bg_color – The background color

  • options – Generator options. See render

Returns

The html code

static _trim(image, transparent, trim_width=True, trim_height=False)[source]

Searches for the first and last non-empty rows and columns and reduces the image to the valid pixels.

Parameters
  • image (ndarray) – The original image

  • transparent (bool) – Defines if the image was transparent and the alpha channel can be used

  • trim_width – Defines if the image shall be reduced horizontally

  • trim_height – Defines if the image shall be reduced vertically

Return type

ndarray

Returns

The trimmed image

static dummy_image()[source]

Returns a dummy image if not data is available

Return type

Image

Returns

Dummy image in the current framework’s representation

render(options=None)[source]

Renders the HTML code to an image

Parameters

options (dict | None) –

One of the following optins can be provided: * html - The website’s full HTML code (if set body & style are

ignored)

  • body - Only the website’s body. You can pass only the content

    code or

the full <body> block

  • style - The site’s style configuration (head.style)

  • width - The rendering width. Otherwise auto detected / clipped at
    1. None by default.

  • height - The rendering height. Otherwise auto detected / no

    limitation. None by default.

  • transparent - Defines if the page shall be rendered onto

    transparent background so an RGBA image will be

created. False by default. * backgroundColor - The color as Color object. White by default. * trimWidth - Automatically reduce the image’s width if the full

extend is not used. True by default.

  • trimHeight - Defines if the height shall be trimmed. False by

    default

Return type

Image

Returns

An image handle

image: np.ndarray | None

The rendered web page