https://github.com/thearchitector/styled-prose
Generate images and thumbnails based on bitmap transformations of rendered prose
https://github.com/thearchitector/styled-prose
art fonts image pdf pdf2image pillow prose render text tgf the-glass-files typography writing
Last synced: about 1 month ago
JSON representation
Generate images and thumbnails based on bitmap transformations of rendered prose
- Host: GitHub
- URL: https://github.com/thearchitector/styled-prose
- Owner: thearchitector
- License: bsd-3-clause
- Created: 2023-12-03T19:40:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-18T04:08:14.000Z (over 2 years ago)
- Last Synced: 2025-02-15T06:48:29.525Z (over 1 year ago)
- Topics: art, fonts, image, pdf, pdf2image, pillow, prose, render, text, tgf, the-glass-files, typography, writing
- Language: Python
- Homepage: https://styledprose.thearchitector.dev/
- Size: 966 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# styled-prose



Generate images and thumbnails based on bitmap transformations of rendered prose.
Documentation: .
Tested support on Python 3.8, 3.9, 3.10, 3.11, and 3.12.
```sh
$ 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.
```toml
# 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.
```python
from PIL import Image
from styled_prose import StyledProseGenerator
text: str = """
This is normal.
This is italicized.
This is bold.
This is bold and italicized.
This is underlined.
This is struck from the record.
"""
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:
