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 获取图片返回 BytesIO,支持指数退避重试
  • URL 图片下载(bytes) (ImageTool.get_img_url_bytes) - 从 URL 获取图片直接返回 bytes,参数同上
  • 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")
im_bytes = pixlib.ImageTool.get_img_url_bytes("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"})

Metadata

Release files for pixlib 1.1.0

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

Built distributions (wheels)

Table of built distributions (wheels) for pixlib 1.1.0
File
pixlib-1.1.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pixlib-1.1.0-cp314-cp314-manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
pixlib-1.1.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pixlib-1.1.0-cp313-cp313-manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
pixlib-1.1.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pixlib-1.1.0-cp312-cp312-manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
pixlib-1.1.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pixlib-1.1.0-cp311-cp311-manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
pixlib-1.1.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pixlib-1.1.0-cp310-cp310-manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pixlib-1.1.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
pixlib-1.1.0-cp39-cp39-manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pixlib-1.1.0-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
pixlib-1.1.0-cp38-cp38-manylinux_2_17_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details

Total release size: 9.7 MB

Release files / pixlib-1.1.0-cp314-cp314-win_amd64.whl

Download URL pixlib-1.1.0-cp314-cp314-win_amd64.whl
Size 171.1 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
9ebbd1b7b653106777e3fd6acaadb0594fc09eb0b11499354222ee20136e85ef
BLAKE2b-256 checksum
How to use checksums
2f550cbb68946f59aea7c991ada306f38807ef3cdda7995489caec661406885e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp314-cp314-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp314-cp314-manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
403716eed2b9e96c20fb9a148cb94667fab6ff40dd2e1870c0212c456edc0b2c
BLAKE2b-256 checksum
How to use checksums
79e04ea3e0827895b85c5907e43ea6dcb7bfd865a40a3aa8cf3cd6e8759174f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp313-cp313-win_amd64.whl

Download URL pixlib-1.1.0-cp313-cp313-win_amd64.whl
Size 168.1 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
cee46a48676396d124bd3b7e72e7c7e4413a408ddf120b7285b9ddf2549eb283
BLAKE2b-256 checksum
How to use checksums
d22f70cf402885e51a7d127992a0f3c27b2c875d9da4d1eb70afed7a7d31692f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp313-cp313-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp313-cp313-manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
56b52e908e9fc1193f7f01a4d9ea4b953afd095d982f259bdbf9138153f31a2e
BLAKE2b-256 checksum
How to use checksums
2ef290af2278a4ffc8ac0e5a1b6123916ba123eccdebc183215810b4291f2ebb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp312-cp312-win_amd64.whl

Download URL pixlib-1.1.0-cp312-cp312-win_amd64.whl
Size 170.0 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
e7ae007a1aaf70243302ba9545e89cd1821a416716b4a571a4398010b0182b71
BLAKE2b-256 checksum
How to use checksums
cd012999622f3c1cbece4b9951aaa43a79a3924d41546cf40c3fbddb83e2a2ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp312-cp312-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp312-cp312-manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
eaf3bd2f7b962cd24ce774d46285ee47bd4f8bb670053a9f055bcdc8fea5b3b3
BLAKE2b-256 checksum
How to use checksums
eafaa7e67474ac340b71caa009f462ead0f05dac2bff13d2ad170b9962459136
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp311-cp311-win_amd64.whl

Download URL pixlib-1.1.0-cp311-cp311-win_amd64.whl
Size 173.5 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
3fdcd816cf5b10ff5f7f72ae55f6157f97bf75348a58a455556cd7af1960e5ca
BLAKE2b-256 checksum
How to use checksums
8d4fe81c1609944feabd1c6ad702f4cb1c67539aff022f0069b40d19b6853697
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp311-cp311-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp311-cp311-manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3a0617ae5dafdfd5fe2a6faa79153f9ddc9245314fdd2ac5cd8fe3c3133d3352
BLAKE2b-256 checksum
How to use checksums
0541cceace6a58ba5c988d82f501d5a37cee06b0cc8984a92622812808bad967
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp310-cp310-win_amd64.whl

Download URL pixlib-1.1.0-cp310-cp310-win_amd64.whl
Size 176.0 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
adb6428987d62ea20dd648e4fc0b1399884426d9570cb3e72a4b557ef1956cca
BLAKE2b-256 checksum
How to use checksums
8920b72f32fcbbb0f9f57d0319aedc8088dc3ba92806fc32ce1dd0f9f17fb454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp310-cp310-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp310-cp310-manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
628a6a4735cf13c35a84428d28107d175bf044838f99f3c53f294929e67352a4
BLAKE2b-256 checksum
How to use checksums
ea60116805773945956b7e937c05e8ce8a85b2d766ba1c78311752ac26e46ec8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp39-cp39-win_amd64.whl

Download URL pixlib-1.1.0-cp39-cp39-win_amd64.whl
Size 177.2 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
1cdb8cf9b7cb6011b1d2122060b0716ae25e3ba4af5f2b6f285ab6006d167658
BLAKE2b-256 checksum
How to use checksums
c584962181a49312780e3d9eeeb96ab1beb25829aa356a58613d9132aa001c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp39-cp39-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp39-cp39-manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9fd92cce21d71d5c80d83fb87121ba41a6351c3fd68d162cb0674ecb52968cc0
BLAKE2b-256 checksum
How to use checksums
131ac9bb7a233b81d7abd6ad19f1f1705e01a6f619e508c07989cb1f84e1902b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp38-cp38-win_amd64.whl

Download URL pixlib-1.1.0-cp38-cp38-win_amd64.whl
Size 168.6 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
fd811fc49f760d57b2774277c2a02b684668ef488de11606130f0ef2a1c0d5ec
BLAKE2b-256 checksum
How to use checksums
342b4cbe908b781756d4e806fd814ed26900c95041bed93a20308d6ccd3ad5fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / pixlib-1.1.0-cp38-cp38-manylinux_2_17_x86_64.whl

Download URL pixlib-1.1.0-cp38-cp38-manylinux_2_17_x86_64.whl
Size 1.1 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1d12a275b48d6ffa4ecff25549a5526be479e88f6b027c1eadbe1349c6951ea2
BLAKE2b-256 checksum
How to use checksums
fde5ec4a185a808dc8db97431a9158ac2edd199eb68289a275d3f39e8f70c032
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Security for pixlib 1.1.0

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.

Full provenance

All 14 files in this release have been uploaded with provenance metadata.

Select from 14 files

Attestation for pixlib-1.1.0-cp314-cp314-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

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