Skip to main content

A simple PIL wrapper and text-to-image tool

Project description

pil-utils

功能

  • 提供 BuildImage 类,方便图片尺寸修改、添加文字等操作
  • 提供 Text2Image 类,方便实现文字转图,支持少量 BBCode 标签

安装

使用 pip 安装:

pip install pil-utils

插件依赖 skia-python 来绘制文字,对于 Linux 平台,需要安装 OpenGL 和 fontconfig:

apt-get install libfontconfig1 libgl1-mesa-glx libgl1-mesa-dri

或:

yum install fontconfig mesa-libGL mesa-dri-drivers

具体安装说明请参考 skia-python 文档

使用示例

  • BuildImage
from pil_utils import BuildImage

# output: BytesIO
output = BuildImage.new("RGBA", (200, 200), "grey").circle().draw_text((0, 0, 200, 200), "测试test😂").save_png()

  • Text2Image
from pil_utils import Text2Image

# img: PIL.Image.Image
img = Text2Image.from_text("@mnixry 🤗", 50).to_image(bg_color="white")

  • 使用 BBCode
from pil_utils import text2image

# img: PIL.Image.Image
img = text2image("N[size=40][color=red]O[/color][/size]neBo[size=40][color=blue]T[/color][/size]\n[align=center]太强啦[/align]")

目前支持的 BBCode 标签:

  • [align=left|right|center][/align]: 文字对齐方式
  • [color=#66CCFF|red|black][/color]: 字体颜色
  • [stroke=#66CCFF|red|black][/stroke]: 描边颜色
  • [font=Microsoft YaHei][/font]: 文字字体
  • [size=30][/size]: 文字大小
  • [b][/b]: 文字加粗
  • [i][/i]: 文字斜体
  • [u][/u]: 文字下划线
  • [del][/del]: 文字删除线

特别感谢

Project details


Download files

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

Source Distribution

pil_utils-0.2.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

pil_utils-0.2.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file pil_utils-0.2.0.tar.gz.

File metadata

  • Download URL: pil_utils-0.2.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for pil_utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 738573fc1f0d3ae4a8df464966cd8b8f440a7281eaa8fc69b44a98997480fe08
MD5 4fa17b67f9ec7b55c2d0582b2d92ec5d
BLAKE2b-256 96588093873bc0d69fbce06e255927354fed5cd8dba0923cfb8ec4d9f01820ff

See more details on using hashes here.

File details

Details for the file pil_utils-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pil_utils-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for pil_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b95009ce13c87243a5ca93b7b68e29dd41ac7398d4c26379475da0f81425ea2
MD5 50a96df4ada30789a6b1c8db79ff6abb
BLAKE2b-256 c718a2b565020c4a73b4f25724a3254c0bd4fb54e504d36b8a23b4c8b0f72ccd

See more details on using hashes here.

Supported by

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