image_transformer.output_builders package
Submodules
image_transformer.output_builders.cairo_svg_output_builder module
This module provides an implementation of the GenericOutputBuilder interface using the Cairo library to render shapes to an SVG file.
- class image_transformer.output_builders.cairo_svg_output_builder.CairoSvgOutputBuilder(width: int, height: int, file_output_path: str)[source]
Bases:
GenericOutputBuilder
An implementation of ShapeRenderer that uses the Cairo library to render shapes to an SVG file.
- add_hexagon(x: int, y: int, size: int, color: Tuple[int, int, int])[source]
Add a flat-topped hexagon to the Cairo canvas.
- add_polygon(vertices: list[Tuple[float, float]], color: Tuple[int, int, int])[source]
Adds a polygon to the Cairo canvas based on the provided vertices and fills it with the specified color.
- Parameters:
vertices (list[Tuple[float, float]]) – A list of (x, y) coordinates for the polygon’s vertices.
color (Tuple[int, int, int]) – The color of the polygon in RGB format (0-255 for each component).
image_transformer.output_builders.generic_output_builder module
This module defines the GenericOutputBuilder abstract base class, which provides an interface for rendering shapes and saving the final output. The class includes methods for adding rectangles and hexagons, as well as saving the rendered output to a file.
- class image_transformer.output_builders.generic_output_builder.GenericOutputBuilder[source]
Bases:
ABC
Abstract base class for shape rendering.
Defines the interface for adding shapes and saving the final output.
- abstract add_hexagon(x: int, y: int, size: int, color: Tuple[int, int, int])[source]
Add a flat-topped hexagon to the output.
- Parameters:
x (int) – The x-coordinate of the top-left point of the hexagon’s bounding box.
y (int) – The y-coordinate of the top-left point of the hexagon’s bounding box.
size (int) – The distance between two opposite sides (the width) of the hexagon.
color (str) – The fill color of the hexagon.
- abstract add_polygon(vertices: list[int, int], color: Tuple[int, int, int])[source]
Abstract method to add a polygon to the output.
- Parameters:
vertices (list[int, int]) – A list of tuples representing the vertices of the polygon.
color (Tuple[int, int, int]) – A tuple representing the RGB color of the polygon.
- abstract add_rectangle(x: int, y: int, size: int, color: Tuple[int, int, int])[source]
Add a square to the output.
- Parameters:
x (int) – The x-coordinate of the square’s top-left corner.
y (int) – The y-coordinate of the square’s top-left corner.
size (int) – The size of the square.
color (str) – The fill color of the square.
image_transformer.output_builders.handmade_svg_output_builder module
A module for generating basic SVG (Scalable Vector Graphics) files. The SVGBuilder class allows you to create an SVG canvas and draw simple shapes, including squares and flat-topped hexagons. The generated SVG can then be saved to a file.
- class image_transformer.output_builders.handmade_svg_output_builder.HandmadeSvgOutputBuilder(width: int, height: int, file_output_path: str)[source]
Bases:
GenericOutputBuilder
An implementation of GenericSvgBuilder that builds SVG content.
Allows users to add squares and hexagons to an SVG canvas and save the output as an SVG file.
- add_hexagon(x: int, y: int, size: int, color: Tuple[int, int, int])[source]
Add a flat-topped hexagon to the SVG at the specified position, size, and colors.
- add_polygon(vertices: list[Tuple[float, float]], color: Tuple[int, int, int])[source]
Add a polygon to the SVG canvas based on the provided vertices and fill it with the specified color.
- Parameters:
vertices (list[Tuple[float, float]]) – A list of (x, y) coordinates for the polygon’s vertices.
color (Tuple[int, int, int]) – The color of the polygon in RGB format (0-255 for each component).
Module contents
This module initializes the output_builders package by importing all functions and classes from the output_builders module.