# styled-prose
![GitHub Workflow Status](https://raster.shields.io/github/actions/workflow/status/thearchitector/styled-prose/ci.yaml?label=tests&style=flat-square)
![PyPI - Downloads](https://raster.shields.io/pypi/dw/styled-prose?style=flat-square)
![GitHub](https://raster.shields.io/github/license/thearchitector/styled-prose?style=flat-square)
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.
```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.
<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:
![example rendering](/docs/simple.jpg)
Raw data
{
"_id": null,
"home_page": "https://styledprose.thearchitector.dev",
"name": "styled-prose",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "prose text writing pdf typography fonts art image render pillow pdf2image tgf the-glass-files",
"author": "",
"author_email": "thearchitector <me@eliasfgabriel.com>",
"download_url": "https://files.pythonhosted.org/packages/6e/a7/4d0e340e66830fbbf89f744de10673681187b22210becbb8c731c605dff4/styled_prose-1.0.0.tar.gz",
"platform": null,
"description": "# styled-prose\n\n![GitHub Workflow Status](https://raster.shields.io/github/actions/workflow/status/thearchitector/styled-prose/ci.yaml?label=tests&style=flat-square)\n![PyPI - Downloads](https://raster.shields.io/pypi/dw/styled-prose?style=flat-square)\n![GitHub](https://raster.shields.io/github/license/thearchitector/styled-prose?style=flat-square)\n\nGenerate images and thumbnails based on bitmap transformations of rendered prose.\n\nDocumentation: <https://styledprose.thearchitector.dev>.\n\nTested support on Python 3.8, 3.9, 3.10, 3.11, and 3.12.\n\n```sh\n$ pdm add styled-prose\n# or\n$ pip install --user styled-prose\n```\n\n## Example\n\nThe following stylesheet is a super simple example that overrides the `default` style's font size and family.\n\n```toml\n# stylesheet.toml\n\n[[fonts]]\nfont_name = \"EB Garamond\"\nfrom_google_fonts = true\n\n[[styles]]\nname = \"default\"\nfont_size = 14\nfont_name = \"EB Garamond\"\n```\n\nUsing 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.\n\n```python\nfrom PIL import Image\nfrom styled_prose import StyledProseGenerator\n\ntext: str = \"\"\"\nThis is normal.\n\n<i>This is italicized.</i>\n\n<b>This is bold.</b>\n\n<i><b>This is bold and italicized.</b></i>\n\n<u>This is underlined.</u>\n\n<strike>This is struck from the record.</strike>\n\"\"\"\nrandom.seed(771999)\n\ngenerator: StyledProseGenerator = StyledProseGenerator(\"stylesheet.toml\")\nimg: Image.Image = generator.create_jpg(\n text,\n angle=-2.5, # optional; an angle by which to rotate the image\n thumbnail=(210, 210), # optional; the dimensions of a random thumbnail\n)\n\nimg.save(\"prose.jpg\", quality=95)\n```\n\nThis above code produces the following image:\n\n![example rendering](/docs/simple.jpg)\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Generate images and thumbnails based on bitmap transformations of rendered prose",
"version": "1.0.0",
"project_urls": {
"Changelog": "https://github.com/thearchitector/styled-prose/blob/main/CHANGELOG.md",
"Documentation": "https://styledprose.thearchitector.dev",
"Homepage": "https://styledprose.thearchitector.dev",
"Repository": "https://github.com/thearchitector/styled-prose"
},
"split_keywords": [
"prose",
"text",
"writing",
"pdf",
"typography",
"fonts",
"art",
"image",
"render",
"pillow",
"pdf2image",
"tgf",
"the-glass-files"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7607e72c575cf48552c8f333a0b9f5f8a1e2f4645e5ef4c716ac12bff6da9a94",
"md5": "667bb06287fb0424f499e24c1d41a4a6",
"sha256": "adc090e27dd531a8990550236fc6a2e08e72be2e6180bd2c171c4e72c2a555f0"
},
"downloads": -1,
"filename": "styled_prose-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "667bb06287fb0424f499e24c1d41a4a6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 13846,
"upload_time": "2023-12-18T04:06:59",
"upload_time_iso_8601": "2023-12-18T04:06:59.733006Z",
"url": "https://files.pythonhosted.org/packages/76/07/e72c575cf48552c8f333a0b9f5f8a1e2f4645e5ef4c716ac12bff6da9a94/styled_prose-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6ea74d0e340e66830fbbf89f744de10673681187b22210becbb8c731c605dff4",
"md5": "e113533412e5368747fdb738802228c8",
"sha256": "360531d3e3ed8cae20b495fadf2e13c4d74e04b485881ed30ec01a05db7068b9"
},
"downloads": -1,
"filename": "styled_prose-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "e113533412e5368747fdb738802228c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 15056,
"upload_time": "2023-12-18T04:07:01",
"upload_time_iso_8601": "2023-12-18T04:07:01.910767Z",
"url": "https://files.pythonhosted.org/packages/6e/a7/4d0e340e66830fbbf89f744de10673681187b22210becbb8c731c605dff4/styled_prose-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-18 04:07:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thearchitector",
"github_project": "styled-prose",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "styled-prose"
}