Skip to main content

pixlib 图像处理工具包

PyPI version Python License Documentation Status

一个轻量级的 Python 图像处理库,专为 AI 图像生成工作流设计。提供纯色图检测、图片有效性校验、透明区域检测、URL 图片下载、MD5 计算、通用 HTTP 请求客户端等实用功能。

主要特性

  • 纯色图检测 (ImageTool.is_plain_gray) - 通过 7 个维度综合判定图片是否为纯色图,支持 bytes / 文件路径 / URL 输入
  • 图片有效性校验 (ImageTool.is_valid_image) - 检测图片是否损坏或不完整,支持 bytes / 文件路径 / URL 输入
  • 透明区域检测 (ImageTool.has_multiple_transparency) - 检测图片是否包含多个透明区域,支持 bytes / 文件路径 / BytesIO / URL 输入
  • 批量透明区域检测 (ImageTool.batch_has_multiple_transparency) - 多线程 + tqdm 进度条批量检测目录下所有图片的透明区域
  • 透明/白色边缘裁剪 (ImageTool.trim_transparent_edges) - 自动裁剪图片的透明/白色边缘并可选添加 padding,支持 bytes / 文件路径 / BytesIO / URL 输入
  • 彩色线条检测 (ImageTool.has_colored_lines) - 检测黑色背景上是否仅包含绿色/红色线条,五重过滤(面积占比 + 颜色纯度 + 双色占比 + 稀疏豁免 + 通道比值)排除填充图/多色图/单色文字/干扰色,支持抗锯齿暗绿色识别,支持 bytes / 文件路径 / BytesIO / URL 输入
  • URL 图片下载 (ImageTool.get_img_url_io) - 从 URL 获取图片,支持指数退避重试
  • MD5 计算 (utils.str_to_md5) - 支持字符串、bytes、文件路径
  • 随机字符串 (utils.generate_random_lowercase) - 生成指定长度的随机小写字母
  • 字节大小转换 (utils.bytes_to_human) - 将字节数转换为人类可读的 B/KB/MB/GB/TB 字符串,支持自动或指定单位
  • HTTP 请求客户端 (HttpRequestClient) - 通用HTTP客户端,支持指数退避重试、GET/POST快捷方法,内置断开ConnectionError重链。

安装

pip install pixlib

使用示例

import pixlib

# 纯色图检测(支持 bytes / 文件路径 / URL)
is_gray, metrics, msg = pixlib.ImageTool.is_plain_gray(image_bytes)
is_gray, metrics, msg = pixlib.ImageTool.is_plain_gray("/path/to/image.png")
is_gray, metrics, msg = pixlib.ImageTool.is_plain_gray("https://example.com/img.png")

# 图片有效性校验(支持 bytes / 文件路径 / URL)
try:
    pixlib.ImageTool.is_valid_image(image_bytes, task_id="abc123")
except Exception as e:
    print(e.extra_data)

# 透明区域检测(支持 bytes / 文件路径 / BytesIO / URL)
has_transparent = pixlib.ImageTool.has_multiple_transparency(image_bytes)

# 批量透明区域检测(多线程 + tqdm 进度条)
results = pixlib.ImageTool.batch_has_multiple_transparency("./images", max_workers=8)
for path, has_trans in results.items():
    if has_trans:
        print(f"有透明区域: {path}")

# 裁剪透明/白色边缘(支持 bytes / 文件路径 / BytesIO / URL)
cropped_bytes = pixlib.ImageTool.trim_transparent_edges(image_bytes, padding=10)
cropped_bytes = pixlib.ImageTool.trim_transparent_edges("/path/to/image.png", padding=20, output_format="WEBP")

# 彩色线条检测(检测黑色背景上的绿色/红色线条)
result = pixlib.ImageTool.has_colored_lines("images/lines.jpg")
print(result)
# {'has_lines': True, 'has_green': True, 'has_red': True, 'green_ratio': 0.5076, 'red_ratio': 0.4819, ...}

# URL 下载图片
im_io = pixlib.ImageTool.get_img_url_io("https://example.com/img.png")

# MD5 计算
pixlib.utils.str_to_md5("hello")
pixlib.utils.str_to_md5("/path/to/image.png")

# 随机字符串
pixlib.utils.generate_random_lowercase(10)

# 字节大小转换
pixlib.utils.bytes_to_human(10515887)              # '10.03 MB'(自动选择单位)
pixlib.utils.bytes_to_human(10515887, unit="KB")   # '10269.42 KB'(指定单位)

# HTTP 请求客户端
client = pixlib.HttpRequestClient(max_retries=3, base_timeout=300)
resp = client.get("https://example.com/api/data")
resp = client.post("https://example.com/api/submit", json={"key": "value"})

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.

pixlib-1.0.7-cp314-cp314-win_amd64.whl (160.0 kB view details)

Uploaded CPython 3.14Windows x86-64

pixlib-1.0.7-cp314-cp314-manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pixlib-1.0.7-cp313-cp313-win_amd64.whl (157.4 kB view details)

Uploaded CPython 3.13Windows x86-64

pixlib-1.0.7-cp313-cp313-manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pixlib-1.0.7-cp312-cp312-win_amd64.whl (158.6 kB view details)

Uploaded CPython 3.12Windows x86-64

pixlib-1.0.7-cp312-cp312-manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pixlib-1.0.7-cp311-cp311-win_amd64.whl (161.7 kB view details)

Uploaded CPython 3.11Windows x86-64

pixlib-1.0.7-cp311-cp311-manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pixlib-1.0.7-cp310-cp310-win_amd64.whl (162.7 kB view details)

Uploaded CPython 3.10Windows x86-64

pixlib-1.0.7-cp310-cp310-manylinux_2_17_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pixlib-1.0.7-cp39-cp39-win_amd64.whl (163.7 kB view details)

Uploaded CPython 3.9Windows x86-64

pixlib-1.0.7-cp39-cp39-manylinux_2_17_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pixlib-1.0.7-cp38-cp38-win_amd64.whl (167.3 kB view details)

Uploaded CPython 3.8Windows x86-64

pixlib-1.0.7-cp38-cp38-manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file pixlib-1.0.7-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 160.0 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9a979ba3bd210228c167d45ffec0748bd030aabe525086c701ee583d0294ca2c
MD5 22ca1b326f7aeb6e599ebe18cb49db4e
BLAKE2b-256 81c179fb7533e31642b55ce0bdb74a0938e9ff5f747fec904abea836f2e50f1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp314-cp314-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp314-cp314-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp314-cp314-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 26aa76510fb94b080a25d905f1c10a781d224fc09313fbacc5362e34c8d91743
MD5 6fd9bc9a47b66443fde349eb5282a21b
BLAKE2b-256 1c79f005a697cbd0fcbac1475c87b38db6910ef09da9f26d4a55d56eb9a90a33

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp314-cp314-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 157.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 92c78f3a2adf8d1b64f7d8290ac229bbbb5e56a4b8c51b3d4988acf665adcb34
MD5 e15cdafdeda775e52cf9720e820bf8a8
BLAKE2b-256 0007ac5eeaefe344e9d95313fdfd9fcc5f765d7f50d696b124f8f652b014e5c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp313-cp313-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp313-cp313-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 94e29c3c365348bea53ca2b559461c268b4966392cc3ff891c12bc8b1a3adfb3
MD5 c5e8f879383f6a072b59c90126183428
BLAKE2b-256 91cfa32e4d250a7db8c5a1837494191d31d44dcf6c097c61c9577d05c4f95982

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp313-cp313-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 158.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 527816d8d77172f1ff286454ef60e8ea06848b8956a3d06d3d5c27c3d8f3f32a
MD5 acbe1b2d3fd22523340c48ef8abf0da1
BLAKE2b-256 0dc5782145a2493a4f51a6bd88407a87a76627f759dcb5ec11f17e0a4024a98a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp312-cp312-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 decc20d41d98e2580a2c0f12659121604a893b4e77d285f0833f6204c02fbf0f
MD5 05c205fa44f5c6fa20b2a6f28371a004
BLAKE2b-256 0286547c49fbcc162ffa5f33f1436888e34558b0e41788c036d71c4b653344f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp312-cp312-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 161.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 81e6f509612ac60b6d3401dfb158dabf20b77a9e5bea7eb3145ef70318669921
MD5 b9cd562226fb0507a573a10460467db6
BLAKE2b-256 87d078a3cf4394c841be4182744b3bdbdec68c109eb959eda05add0bd90ea9f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp311-cp311-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 43daba5c11d9e51da6bc224d9529e4b7fa1f5f867109b4ae87f2bd99c74ba05d
MD5 82b355aae184aa211c843411a48569a4
BLAKE2b-256 47827d24595a1f9fcb6698fff7b4f31402bb3269231acd47ff4ee7fbacd36d60

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp311-cp311-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 162.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 53a8e7a0bf0cf82dd9455a9e2773431c4e3d16fc2863fdf329ceb0eb06418000
MD5 d9cd36437ed6fd52f0c9e12b2b1c9ee1
BLAKE2b-256 4f65fb5b8fabf511ec82bb8f97d97910ceeabcf82d5f5a61d3703427404054ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp310-cp310-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp310-cp310-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 040e5fb2da2afea317d055da1d01c51fe947969b341b557c1af8b40e0446d8d8
MD5 01316d26332a149917560aeb0eeda32a
BLAKE2b-256 b48e4b54db5cdce6e7eec454ac7858808232374a2b3628e87c97a58d5c4920a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp310-cp310-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 163.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7d64ee5487c0414b372da6328910e4b136ed2981cc94d3f7b564bda739e95191
MD5 c4dd7b2fd524075a5471c001bab37464
BLAKE2b-256 9f75790a1c0d5142ca156ce857b91aac364cf102be44c122df8730fa38372f58

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp39-cp39-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp39-cp39-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp39-cp39-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 86900bf2082da2474f82f7c7de0a024d59f7b352f3edebe55b51706f441676c3
MD5 9916e05a9aee84225daccefd56e850c8
BLAKE2b-256 719f803932c41bd917410412996850f92cf2063fcefbe6a1cffcab613844a5e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp39-cp39-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pixlib-1.0.7-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 167.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixlib-1.0.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a605c69a4def64f5990d7d3302f14cb3588f0bac6983bfffb4713f8df510be19
MD5 dfc81935316457d6ab7f2397936d46c2
BLAKE2b-256 3229cfdcbb1e2f74a4c7fa2703fe8283add562441051037c0c4fd73867409fc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp38-cp38-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixlib-1.0.7-cp38-cp38-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pixlib-1.0.7-cp38-cp38-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8d3b9e5e91bdc4ef4e7b7dacf7ed15c627dd29a7879d6e80053b58710ce408ad
MD5 9a31621b38d7bd08d983c790e2dcd2d6
BLAKE2b-256 5e98ea7511075257a018973559a2507a3acb87ffd30607b26ac55ce54f4caaad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixlib-1.0.7-cp38-cp38-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322-package/pixlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.7 This release

14 files

1.0.6

14 files

1.0.5

14 files

1.0.4

14 files

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