Skip to main content

text2png

通过文本生成图片,会自动计算折行,默认使用自带的等距更纱黑体(简体中文)字体

安装

pip install impaper

使用

默认提供了一个能够生成黑底白字的文本渲染器:

from impaper import SimpleTextDrawer


std = SimpleTextDrawer()
std.conf.typesetting.indentation = ">>>"
im = std.draw(
    "abcdefg,abcdefg,abcdefg\n"
    "你好世界,你好世界,你好世界。\n"
    "你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,你好世界,"
)

生成结果:

example1

SimpleTextDrawer 的可配置项直接修改其属性即可,在文档字符串中有描述:

  • self.fontsize : 字号,默认14
  • self.fg_color : 字体颜色,默认白色 0xff
  • self.bg_color : 背景颜色,默认黑色 0x00
  • self.ts.line_width : 折行宽度,单位是字,默认 48
  • self.ts.indentation : 折行缩进符号,字符串,默认两个空格
  • self.conf.font.path : 重新指定一个字体,需要输入 TTF 格式的字体路径
  • self.conf.layout.margin : 上右下左顺序的四元组,单位 px,默认全 6px
  • self.conf.layout.padding : 上右下左顺序的四元组,单位 px,默认全 2px
  • self.conf.layout.spacing : 行距,单位 px,默认 2px

Metadata

Release files for impaper 0.1.6

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

Source distribution (sdist)

Source distribution for impaper 0.1.6
File Size Uploaded Provenance Actions
impaper-0.1.6.tar.gz 12.4 MB Without provenance Details for impaper-0.1.6.tar.gz

Release files / impaper-0.1.6.tar.gz

Download URL impaper-0.1.6.tar.gz
Size 12.4 MB
Tags Source
SHA-256 checksum
How to use checksums
ee2b36817db7017225409fb3a2ac70daa18983ef32632257f5f53f49c7add47d
BLAKE2b-256 checksum
How to use checksums
3e22484003269baf8eaac0acd1a57574a46e05b9cadfcbb15f8736f74ef8387b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.4.9 CPython/3.11.2

Security for impaper 0.1.6

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