Code Monkey home page Code Monkey logo

styled-prose's Introduction

styled-prose

GitHub Workflow Status PyPI - Downloads GitHub

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:

example rendering

styled-prose's People

Contributors

thearchitector avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.