Skip to main content

pyfont

Documentation

生成文字图片:在一定的区域,支持换行,丢弃,缩小来完成适应区域 The documentation is hosted at https://github.com/BingerYang/pyfont

Installation

pip install pyfont

Usage

example: 1. write 通过控制 limit_width 与 传入回调返回,决定是否换行,或者丢弃

# -*- coding: utf-8 -*-
from pyfont import FontAttr, FontDraw
from PIL import Image

image = Image.new('RGBA', (int(400), int(400)), (255, 255, 255, 0))
font = FontAttr(size=20, limit_width=220)
obj = FontDraw(bg=image, font=font)

# 通过控制 limit_width 与 传入回调返回,决定是否换行,或者丢弃
# progress=None 超过不处理
# progress 返回值有空,丢弃多余,返回多余的 line[index:](换行处理)
def progress(index, line):
    print('index:', index, line[index:])
    # return line[index:]
    pass


offset = obj.write(text="我们是中国人,我爱我的祖国\n你好", progress=progress)
img = obj.crop(offset)
print(img.size)
img.show()
print(font.size, font.line_height)
  1. write_by_change_size 通过 limit_width, limit_height 适当的缩小字体范围,以适应区域

from pyfont import FontAttr, FontDraw
from PIL import Image

image = Image.new('RGBA', (int(400), int(400)), (255, 255, 255, 0))
font = FontAttr(size=20, limit_width=220)
obj = FontDraw(bg=image, font=font)

offset = obj.write_by_change_size(text="我们是中国人,我爱我的祖国\n你好")
img = obj.crop(offset)
img.show()

Metadata

Release files for pyfont 0.0.1.20021123

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfont 0.0.1.20021123
File Size Uploaded Provenance
pyfont-0.0.1.20021123.tar.gz 5.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfont 0.0.1.20021123
File Interpreter ABI Platform
pyfont-0.0.1.20021123-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 kB

Release files / pyfont-0.0.1.20021123.tar.gz

Download URL pyfont-0.0.1.20021123.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
484a0d7071ca4398a0d407673da69f6e9f085a8afff7b9d01c9b265c0e1d633c
BLAKE2b-256 checksum
How to use checksums
4a37216bf019ca4d08fa8efc09ad64f4047d9f8ae12d4da70a1f330a9c16ed98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4

Release files / pyfont-0.0.1.20021123-py3-none-any.whl

Download URL pyfont-0.0.1.20021123-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e6e2f2c0ee2812c3e8a1acd140e3165a8baaf16f1b4904a962156040696a11f
BLAKE2b-256 checksum
How to use checksums
a642491557111c68cfc031d02e8317fb21a756f265ad5079c3e78aba90fbb855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4

Security for pyfont 0.0.1.20021123

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page