Skip to main content

Python bindings for imagetext

Project description

hero banner

A blazing fast text drawing library

imagetext-py is python bindings for imagetext

pypi Downloads PythonVersions discord


if you found this library useful, consider leaving a star ⭐

About

imagetext makes use of rusttype for font parsing and tiny-skia for drawing. It has a simple API that allows you to draw text with ease.

Currently imagetext-py does beat out Pillow for most of the cases I've tested, but I will setup some benchmarks soon.

Features

  • Multi-line text
  • Text wrapping
  • Text alignment
  • Font fallbacks
  • Text stroke
  • Gradient fills
  • Emojis! (almost every platform supported, including discord)
  • Global Font Database with css-like font querying

Note: emojis are fetched and cached from the internet during runtime, so you will need an internet connection to use them. The ability to use local emoji images will be added soon.

Installation

pip install imagetext-py

Example Usage

from PIL import Image
from imagetext_py import *

# supports fonts with fallbacks
FontDB.LoadFromDir(".")
font = FontDB.Query("coolvetica japanese")

# create a canvas to draw on
cv = Canvas(512, 512, (255, 255, 255, 255))

# paints are used to fill and stroke text
black = Paint.Color((0, 0, 0, 255))
rainbow = Paint.Rainbow((0.0,0.0), (256.0,256.0))

# if a font doesn't have a glyph for a character, it will use the fallbacks
text = "hello my 😓 n🐢ame i☕s 会のすべ aての構成員 nathan and i drink soup boop coop, the quick brown fox jumps over the lazy dog"

draw_text_wrapped(canvas=cv,              # the canvas to draw on
                  text=text,
                  x=256, y=256,           # the position of the text
                  ax=0.5, ay=0.5,         # the anchor of the text
                  size=67,                # the size of the text
                  width=500,              # the width of the text
                  font=font,
                  fill=black,
                  align=TextAlign.Center,
                  stroke=2.0,             # the stroke width (optional)
                  stroke_color=rainbow,
                  draw_emojis=True)   # the stroke color (optional)

# you can convert the canvas to a PIL image
im: Image.Image = cv.to_image()
im.save("test.png")

# or you can just get the raw bytes
dimensions, bytes = cv.to_bytes()

# you can also save directly to a file
cv.save("test.png")

produces this image:

test.png

Pillow and FontDB Usage

from PIL import Image
from imagetext_py import *

FontDB.SetDefaultEmojiOptions(EmojiOptions(parse_discord_emojis=True))
FontDB.LoadFromDir(".")

font = FontDB.Query("coolvetica japanese")

with Image.new("RGBA", (512, 512), "white") as im:
    with Writer(im) as w:
        w.draw_text_wrapped(
            text="hello from python 😓 lol, <:blobpain:739614945045643447> " \
                 "ほまみ <:chad:682819256173461522><:bigbrain:744344773229543495> " \
                 "emojis workin",
            x=256, y=256,
            ax=0.5, ay=0.5,
            width=500,
            size=90,
            font=font,
            fill=Paint.Color((0, 0, 0, 255)),
            align=TextAlign.Center,
            stroke=2.0,
            stroke_color=Paint.Rainbow((0.0,0.0), (256.0,256.0)),
            draw_emojis=True
        )
    im.save("test.png")

produces this image:

test.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

imagetext_py-2.2.1-cp38-abi3-win_arm64.whl (3.7 MB view details)

Uploaded CPython 3.8+Windows ARM64

imagetext_py-2.2.1-cp38-abi3-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.8+Windows x86-64

imagetext_py-2.2.1-cp38-abi3-win32.whl (3.7 MB view details)

Uploaded CPython 3.8+Windows x86

imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_i686.whl (6.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_armv7l.whl (6.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_aarch64.whl (7.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (7.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (6.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (6.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (8.2 MB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1fa5b6023146391bb0b840e097f53d62e1ba7bb4f11ae2a83e74168eb1c69543
MD5 fd9d9e83e230f8a01aa6a300e0812e29
BLAKE2b-256 a39c40c0b8898d19ef2ace536350b5d61adab714e33b7584c22e53711d7741c4

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4a246cb6522d6a9723faff6911ac589ff54d7371a7dc831195d9b672063ddc7a
MD5 73b217bd3d8427afc95dff63beb96241
BLAKE2b-256 09bc86539bf10812052a3543179a6d60c2ff5f47766674c9272a09a49a87d164

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-win32.whl.

File metadata

  • Download URL: imagetext_py-2.2.1-cp38-abi3-win32.whl
  • Upload date:
  • Size: 3.7 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 92f3affe30725394c9bd0be29bedcd6f8583fcc5a2f6c1b4069019bc82ea08aa
MD5 586503d73c32519d73dad6a39855a7be
BLAKE2b-256 e7920913dc58f0310b5eed33efb60255356959ab5d309335ddb4ef7cc60c88e0

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0cb4dfba512a2049d336675b69454c578175e7c3e78ca0bf13406c75baa16087
MD5 6ecf131b508ac8142093881411545765
BLAKE2b-256 edbef79931b3feaae62e0d58b685026656bd8cf3891f1e9263ae5d7aec07e6ac

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ec3c24aa117eece6a31e6876d8dd44578acb07ad135537ecf77aeb42da7364c1
MD5 e5a47aced8c7b86385b53a2d840a7886
BLAKE2b-256 f3b18442d4e58e312409f3b8a95438b6adf2168574a80b21cde06f826476ec31

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 61cf6b8f746a22bf7b06a013e56c3f364a21bf5b10bc28f7b72d4df9c38d443c
MD5 82e58002d52080b4beafbce889d621ac
BLAKE2b-256 5b2378fa31a1f5c423f09ea8b351576ab1a72a3df54c2f592fe13cddff7b0787

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e6af78fe8af536698599c784f55efea68d685441c0d718e4606a0c6f451d8646
MD5 43704ce41531845038f071d0bd0d5712
BLAKE2b-256 de7511635275dba7e00daa62df084b3af63f5a6d7a183ca061affd49da3e6643

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60aaacd5aa24383e6c0ae8d132de5db882eef733b38d05a70fc90bfa70d198ea
MD5 2d87283cab96e7a02c4383b474d8832c
BLAKE2b-256 d6f031e3e12eae7469c8f23de3fce0ca1fb890c3ecafe1d97f0b9cb2be58d0e1

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 c2d5b8b941740a51839ac7a5933e6a50b58b8717cc275b9964b8bd1e0d80491d
MD5 a8a9d40eef6de728f53457c4af6b6471
BLAKE2b-256 367712711b5224c01bd48f1ce62634a2eadba2139317dc5a5036307dea163bed

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 cb955668bfb510f7fbaf321022fb85bbbb4397252d572145fa1553e23f85e2f4
MD5 d58f4efa2958ed554b9b8fcca2e496f7
BLAKE2b-256 ca35b9776e5f4792f2f926dcd8c14fc5594542e84a9822a156788c9e9aa0c72e

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 11e3cbd880a7278a84e0b38f8c043d3684dec2f25b5e37b4dc3d837229137fda
MD5 f7add094273a12cc4205fe038bc7663d
BLAKE2b-256 67f228a05ce142ac86d549cc5c54dbe0b9154b4ef1db57a45906667afb9de1c6

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8f71ca6ccfa23ff8858fb2777c5ac5fdf22ecef2e71b8cc23e1a8e444df17065
MD5 870f4b5b4cb771eadb07b56968296cee
BLAKE2b-256 1543461016dac0e81a52b0e50d321be5d1a16b827b127b52f583f85db00f3ce7

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 71908e62705fa1fb5cd1c4f74fc5e0b4b6e1d24d87ea9be9c45bd3196c3be05f
MD5 980f7ef40a971930be014092fa19c239
BLAKE2b-256 d30c1e9840be92b2f1aa4fe65f65b64475f377fd0a04e838040fa5e4d789dc9f

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cb376bef61643c2e7ae56dff1c8dbc21a676cdf065a76946541661837b325413
MD5 165e31842a046a19e0b31bbf219c0b51
BLAKE2b-256 cdfd1f0e9b1d90a47cf25f8cf340dca99d3f4ff1d67e0e9d9a5ccbbe43530cb4

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 27079cbe39410f06637e6ef24c735888b26332c97a22c97e13ae7854be312a2d
MD5 8047499992bdc2d9cd3adf35229a5b5c
BLAKE2b-256 7ea635cb4e1e17897c94e51dae170f32bae424931dfcd28b93ba5718318a911b

See more details on using hashes here.

File details

Details for the file imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a1702c9584c1ea69790ec0cbc918a8cb73047926d8228303948ee065c6785629
MD5 9439d95541b38c25b215e7e9a5c5274b
BLAKE2b-256 16da6dbf5d493b9f7363755414de54d92cb016a81c017c9bc17f0eb9a3b993d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page