Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about tapita

New minisite: book covers

Since I wrote tapi­ta to au­to­mat­i­cal­ly cre­ate book cov­er­s, it was ab­surd­ly easy to turn it in­to a site where you can cre­ate book cov­er­s.

So, you can go to Cov­er­s.ralsi­na.me and cre­ate book cov­er­s.

Fun part: this is the whole back­end for the site:

from json import loads
from tapita import Cover
from io import BytesIO
import base64


def handle(req):
    """handle a request to the function
    Args:
        req (str): request body

    {
        "title": "foo",
        "subtitle": "bar",
        "author": "bat",
    }
    """
    try:
        args = loads(req)
    except Exception:
        return "Bad Request", 400

    c = Cover(**args)
    byte_arr = BytesIO()
    c.image.save(byte_arr, format="JPEG")

    return (
        f'<img src="data:image/jpeg;base64, {base64.b64encode(byte_arr.getvalue()).decode("utf-8")}">',
        200,
        {"Content-Type": "text/html"},

New project: Tapita

For rea­sons I won't dis­cuss, I need­ed to cre­ate a bunch of ebook cov­er­s. Look­ing around I found some code to do it pro­gram­mat­i­cal­ly, so I adapt­ed/rewrote it and now pub­lished my ver­sion.

More in­for­ma­tion at the tapi­ta github re­po

And here's an ex­am­ple cov­er:

It does enough for what I need, but hap­py to work a bit more on it if any­one wants it.


Contents © 2000-2023 Roberto Alsina