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

CI

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.

Features

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

Installation

pip install imagetext-py

Example Usage

from PIL import Image
from imagetext_py import *

# supports fonts with fallbacks
font = Font("coolvetica.ttf", fallbacks=["emojis.ttf", "japanese.otf"])

# 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)   # 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

took 6ms to draw this on my machine

Pillow and FontDB Usage

from PIL import Image
from imagetext_py import *

FontDB.SetDefaultEmojiOptions(EmojiOptions(allow_discord=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=512,
            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")

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

imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

imagetext_py-2.0.1-cp311-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11Windows x86-64

imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (8.4 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

imagetext_py-2.0.1-cp310-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (8.4 MB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

imagetext_py-2.0.1-cp39-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.9Windows x86-64

imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (8.4 MB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

File details

Details for the file imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c370b06c1a84ed9f28bc939c401269097266802437cd344b10dd8fca152921f
MD5 7abcbc6e21bdf18732cc6aede80b0172
BLAKE2b-256 b5b4def635e818b1e78a28201f22c0addfe4fe57c712f08ce59dc5f3618e7236

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 286da2ed58ff2717798fda97aa15c1bf3bf390c1244675a39f407b30f82e431f
MD5 2a9128a060587225b5f5ad9eb1ffd1b2
BLAKE2b-256 303560e02111ccc29a8a1600257d94d570df7829911d3c56d9b01f669ff3f72e

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4d1437c32d60c5ab36db8c31c04b3b2fddd7c34086147adfac787c30cc9c7f8
MD5 ebf67fcfab0638f451acc7beadbb3074
BLAKE2b-256 d23d770906e5f914e2ffbee2239645402c9fac97fd459dfbdf5e3c12008cdf6a

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 06774d4a1cd1865232e51456f784d259481e17522766fe22eb7fd77e16ca5717
MD5 65ebdac6d75aec0a5d2f12cf9f2748f3
BLAKE2b-256 04ec2a606b2e96b1a22f68a73ce80d4057328ca255e7bdbb86f4b7841535eda7

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 f1390275fb79caf016d2c9c687844fcb825ae152033c73897f5915a575676af6
MD5 eb012a7fbab50ed802585389dec643fc
BLAKE2b-256 560609904578566de84b90d15805995b3da2f76d11aa8cc4432965f301cdfe69

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 44d812e0eaed64045b98973291f1afbef56f757351ecd328faac1b777ea03411
MD5 f33d2855d9fc03fd04a4e0c5a827769b
BLAKE2b-256 29fa6ed42851bc4f7dce77bdb4605192166a57253263ad4d77bc1a0b940dfd46

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0324160d5ebac225fb33af17bcdbd81fa322f6d312c92d39a462cbfd85e289ca
MD5 e02c7a23077abeab341cfa80a06099b6
BLAKE2b-256 7dac8307ca9127f253d11e57267b7a25c044966e48d006296e480215db6ac6af

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 265b0df76ad86c3b924711f84b2bd1cdf8500d9fd19553830cbb69f701707194
MD5 2d25a475a4fc9f9f0883bb882dca6b50
BLAKE2b-256 0f2a83bfc0423019deb370f8b454e219f442d6f71f2b5879dcb8e7f229c197df

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a485150f3e929e87725c80a2706e1d94457770d33cbf6720e275bfb074d532c0
MD5 94e8dd9fcb712310893b7e53e9c06abb
BLAKE2b-256 df61542b67c7949d6a7d42146c3d7c7e0a41c8cb51352384fcc2576189e42395

See more details on using hashes here.

File details

Details for the file imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0c8321787bb9f137552d7f707c2a16c3e195f99de0f04e1bc74529b82b66e0b4
MD5 61f18e597685042d9615713da7740510
BLAKE2b-256 a9f7b6d9002e44bb0891ee8b45d7f64bd1bfde08ce8e79f25b02433821b507a0

See more details on using hashes here.

Supported by

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