Skrivener is a service that accepts text and typesets it into an image. This service communicates over ZeroMQ protocol using JSON formatted messages.
Features:
- Accepts up to 250 characters of UTF-8 text
- PNG format
- Pleasant default color pairings
- Unsurprising interfaces
- JSON messages
- Base64 encoding
- Clone this repository
- Enter or initialize a Python virtual environment*
- Install this repo with
$ pip install .
- Run this project
- either execute
$ skrivener
(this command is placed in your $PATH by PIP) - or execute
$ python -m skrivener
- either execute
Skrivener reads some environment variables on initialization. The provided defaults are:
host=*
port=8672
loglevel=info
You can change these in the .env.example
file provided, make your own .env
, or set these environment variables another way.
* for more on this see the Python Packaging Authority's introduction
The accepted parameters for generating an image are:
- text:
- required: Yes
- type:
string
- constraints: 1-250 characters
- colors:
- required: No
- default: a color pairing will be selected from the default palettes
- type:
object
- constraints
- both keys are required
- value formats must be valid hex color codes
- optional "#" prefix, 3 or 6 digits, characters [0-9, a-f, A-F] only
- keys:
- "bg":
string
- "text":
string
- "bg":
- required: No
{
"text": "Traditionally, art has been for the select few. We have been brainwashed to believe that Michaelangelo had to pat you on the head at birth. Well, we show people that anybody can paint a picture that they're proud of -- Bob Ross"
}
or, specifying the colors:
{
"text": "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.",
"colors": {
"text": "#fff",
"bg": "#000"
}
}
All Skrivener responses have one common key:
- status
- required: Yes
- type:
string
- status
- required: Yes
- type: literal string
ok
- image:
- required: Yes
- type:
string
- info
- this is a base64 encoded PNG file (for instructions on usage, see below)
{
"status": "ok",
"image": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIA (...)"
}
- status
- required: Yes
- type: literal string
error
- message
- required: Yes
- type:
string
- info
- provides context for what went wrong
In this example, we sent one malformed color (#0fg).
{
"status": "error",
"message": "unknown color specifier: '#0fg'"
}
Because Skrivener uses Pydantic for data validation, any formatting or validation errors should be human readable.
To decode the Base64 string in Python, use (the base64 module)[https://docs.python.org/3/library/base64.html]:
import base64
image_encoded = "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIA (...)"
image_bytes: bytes = base64.b64decode(image_encoded)
Then, you may write that image out to disk using open
with open("/your/file/here.png", "wb") as file:
file.write(image_bytes)
or read using Pillow
bytes_buffer = io.BytesIO(image_bytes)
image = im.open(bytes_buffer)
# do anything with image!
image.show() # will open in your system viewer
Also see the test client script in the repo at (/tests/client.py)[/tests/client.py#L52-L58]
Skrivener uses
- Pillow for image manipulation
- Pydantic for data validation
- pyzmq for ZeroMQ communication
- Poetsen One font, designed by Rodrigo Fuenzalida, Pablo Impallari