102 lines
2.7 KiB
Markdown
102 lines
2.7 KiB
Markdown
# PyWebLayout
|
|
|
|
## Project Status
|
|
|
|
| Badge | Description |
|
|
|-------|-------------|
|
|
|  | **Test Coverage** - Percentage of code covered by unit tests |
|
|
|  | **Documentation Coverage** - Percentage of code with docstrings |
|
|
|  | **Build Status** - Current CI/CD pipeline status |
|
|
|  | **License** - Project licensing information |
|
|
A Python library for HTML-like layout and rendering.
|
|
> 📋 **Note**: Badges show results from the commit referenced in the URLs. Red "error" badges indicate build failures for that specific step.
|
|
## Description
|
|
|
|
PyWebLayout provides classes for rendering HTML-like content to images using a box-based layout system. It includes support for text, tables, and containers, as well as an HTML parser for converting HTML to layout objects.
|
|
|
|
## Features
|
|
|
|
- HTML-like layout system
|
|
- Text rendering with font support
|
|
- Table layouts
|
|
- Container elements
|
|
- HTML parsing
|
|
- Image output
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install pyWebLayout
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Basic Example
|
|
|
|
```python
|
|
from pyWebLayout.concrete.page import Page, Container
|
|
from pyWebLayout.abstract.inline import Line
|
|
from pyWebLayout.layout import Alignment
|
|
from PIL import ImageFont
|
|
|
|
# Create a page
|
|
page = Page(size=(800, 600), background_color=(240, 240, 240))
|
|
|
|
# Add a title container
|
|
title_container = Container(
|
|
origin=(0, 0),
|
|
size=(780, 60),
|
|
direction='horizontal',
|
|
spacing=10,
|
|
padding=(10, 10, 10, 10),
|
|
halign=Alignment.CENTER,
|
|
valign=Alignment.CENTER
|
|
)
|
|
page.add_child(title_container)
|
|
|
|
# Create a title line with text
|
|
title_font = ImageFont.load_default()
|
|
title_line = Line(
|
|
spacing=(8, 15),
|
|
origin=(0, 0),
|
|
size=(760, 40),
|
|
font=title_font,
|
|
text_color=(0, 0, 0),
|
|
halign=Alignment.CENTER
|
|
)
|
|
title_container.add_child(title_line)
|
|
title_line.add_word("PyWebLayout", title_font)
|
|
title_line.add_word("Example", title_font)
|
|
|
|
# Layout and render the page
|
|
page.layout()
|
|
image = page.render()
|
|
image.save("example.png")
|
|
```
|
|
|
|
### HTML Example
|
|
|
|
```python
|
|
from pyWebLayout.html_parser import html_to_image
|
|
|
|
html = """
|
|
<div style="text-align: center; padding: 10px;">
|
|
<h1>PyWebLayout HTML Example</h1>
|
|
<p>This is a paragraph rendered from HTML.</p>
|
|
<p>The library supports <b>bold</b>, <i>italic</i>, and <u>underlined</u> text.</p>
|
|
</div>
|
|
"""
|
|
|
|
# Render HTML to an image
|
|
image = html_to_image(html, page_size=(800, 600))
|
|
image.save("html_example.png")
|
|
```
|
|
|
|
## License
|
|
|
|
MIT License
|
|
|
|
## Author
|
|
|
|
Duncan Tourolle - duncan@tourolle.paris
|