Generate images and thumbnails based on bitmap transformations of rendered prose
Project description
styled-prose
Generate images and thumbnails based on bitmap transformations of rendered prose.
Documentation: https://styledprose.thearchitector.dev.
Tested support on Python 3.8, 3.9, 3.10, 3.11, and 3.12.
$ pdm add styled-prose
# or
$ pip install --user styled-prose
Example
The following stylesheet is a super simple example that overrides the default
style's font size and family.
# stylesheet.toml
[[fonts]]
font_name = "EB Garamond"
from_google_fonts = true
[[styles]]
name = "default"
font_size = 14
font_name = "EB Garamond"
Using that stylesheet, and some basic prose, you can generate an image. The requested font family EB Garamond
and its license are downloaded from Google Fonts and cached automatically; subsequent generations use those cached fonts.
from PIL import Image
from styled_prose import StyledProseGenerator
text: str = """
This is normal.
<i>This is italicized.</i>
<b>This is bold.</b>
<i><b>This is bold and italicized.</b></i>
<u>This is underlined.</u>
<strike>This is struck from the record.</strike>
"""
random.seed(771999)
generator: StyledProseGenerator = StyledProseGenerator("stylesheet.toml")
img: Image.Image = generator.create_jpg(
text,
angle=-2.5, # optional; an angle by which to rotate the image
thumbnail=(210, 210), # optional; the dimensions of a random thumbnail
)
img.save("prose.jpg", quality=95)
This above code produces the following image:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for styled_prose-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc090e27dd531a8990550236fc6a2e08e72be2e6180bd2c171c4e72c2a555f0 |
|
MD5 | 667bb06287fb0424f499e24c1d41a4a6 |
|
BLAKE2b-256 | 7607e72c575cf48552c8f333a0b9f5f8a1e2f4645e5ef4c716ac12bff6da9a94 |