Skip to main content

一个功能强大的图片处理工具箱

Project description

LeviCanvas - 图片处理工具箱

PyPI version Python versions License: MIT

LeviCanvas 是一个功能强大的图片处理工具箱,提供了丰富的图片处理功能,包括图片压缩、圆角处理、渐变效果、文本绘制、二维码生成等。

功能特性

  • 🖼️ 图片处理: 压缩、缩放、圆角化、圆形裁剪
  • 🎨 图形绘制: 半透明区域、纯色圆角矩形、渐变图片
  • ✏️ 文本处理: 文本绘制、居中显示、多行文本处理
  • 📊 进度条: 线性进度条、圆环进度条
  • 🔲 二维码生成: 普通二维码、带头像二维码
  • 🌐 网络图片: 从URL加载图片
  • 🎭 特效处理: 高斯模糊、透明渐变

安装

使用 pip 安装:

pip install levicanvas

快速开始

from levicanvas import LeviCanvas
from PIL import Image

# 压缩图片
LeviCanvas.compress_image("input.jpg", "output.jpg", quality=80)

# 从URL加载图片
img = LeviCanvas.load_image_from_url("https://example.com/image.jpg")

# 创建圆角图片
rounded_img = LeviCanvas.get_round_image(img, radius=20)

# 生成二维码
qr_img = LeviCanvas.generate_qr_code("https://example.com")

# 绘制文本
font = ImageFont.truetype("arial.ttf", 24)
img = LeviCanvas.Draw_Text(img, font, (10, 10), (0, 0, 0), "Hello World")

主要功能

图片处理

压缩图片

# 压缩图片到指定质量
success = LeviCanvas.compress_image("input.jpg", "output.jpg", quality=80)

圆角处理

# 普通圆角
rounded_img = LeviCanvas.get_round_image(img, radius=20)

# 自定义圆角(左上、右上、左下、右下)
rounded_img = LeviCanvas.get_round_imageEx(img, radius=20, type=(1, 1, 0, 0))

# 纯色圆角矩形
color_rect = LeviCanvas.get_solidColorRound_image(200, 100, (255, 0, 0), radius=10)

圆形图片

# 创建圆形图片
circular_img = LeviCanvas.get_circular_image(img, radius=100)

图片缩放

# 等比例缩放,自动填充空白
resized_img = LeviCanvas.zoom_img(img, width=500, height=300, alpha=True)

图形绘制

半透明区域

# 在图片上创建半透明区域
translucent_img = LeviCanvas.get_translucent_area(
    img, 
    area=(10, 10, 100, 100),  # (x1, y1, x2, y2)
    color=(255, 0, 0, 128),    # RGBA
    _radius=10
)

渐变图片

# 创建渐变图片
gradient_img = LeviCanvas.get_gradient_image(
    width=200,
    height=100,
    start_color=(255, 0, 0),
    end_color=(0, 0, 255),
    direction=1  # 1:左到右, 2:上到下, 3:左上到右下, 4:左下到右上
)

文本处理

基本文本绘制

font = ImageFont.truetype("arial.ttf", 24)
img = LeviCanvas.Draw_Text(img, font, (10, 10), (0, 0, 0), "Hello World")

居中文本

# 在指定区域内居中显示文本
img = LeviCanvas.Draw_TextMax(
    img, 
    font, 
    area=(0, 0, 200, 100),  # (x, y, width, height)
    color=(0, 0, 0),
    text="Centered Text"
)

高级文本处理

# 多行文本,自定义间距和对齐方式
img = LeviCanvas.Draw_TextMaxEX(
    img,
    font,
    area=(0, 0, 200, 100),
    clearance=5,  # 行间距
    color=(0, 0, 0),
    text="Line 1\nLine 2\nLine 3",
    mid=True  # 居中显示,False为左对齐
)

进度条

线性进度条

font = ImageFont.truetype("arial.ttf", 24)
img = LeviCanvas.draw_progress_bar(
    img,
    font=font,
    progress=0.75,  # 0.0-1.0
    text="75%",
    area=(50, 50, 250, 100),  # (x1, y1, x2, y2)
    auto=True  # 自动根据进度值变色
)

圆环进度条

img = LeviCanvas.draw_circle_outline(
    img,
    font=font,
    progress=0.6,  # 0.0-1.0
    text="60%",
    point=(200, 200),  # 圆心坐标
    radius=100,
    thickness=20,
    auto=True  # 自动根据进度值变色
)

二维码生成

普通二维码

# 基本二维码
qr_img = LeviCanvas.generate_qr_code("https://example.com")

# 自定义样式二维码
config = {
    "version": 1,
    "box_size": 10,
    "border": 2,
    "fill_color": "black",
    "back_color": "white"
}
qr_img = LeviCanvas.generate_qr_code("https://example.com", config=config)

带头像的二维码

# 生成带头像的二维码
qr_with_logo = LeviCanvas.generate_qr_code_with_logo(
    "https://example.com",
    config=config,
    logo_path="logo.png"
)

特效处理

高斯模糊

# 对指定区域应用高斯模糊
blurred_img = LeviCanvas.apply_gaussian_blur(
    img,
    box=(50, 50, 150, 150),  # (left, upper, right, lower)
    radius=10
)

透明渐变

# 从指定位置开始透明渐变
gradient_img = LeviCanvas.grad_transparent_rectangle(img, y_begin=100)

依赖项

  • Pillow >= 9.0.0
  • httpx >= 0.24.0
  • qrcode >= 7.4.0

许可证

本项目采用 MIT 许可证。详见 LICENSE 文件。

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

v1.0.0

  • 初始版本发布
  • 包含所有核心图片处理功能
  • 支持圆角、渐变、文本绘制、二维码生成等功能

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

levicanvas-1.0.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

levicanvas-1.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file levicanvas-1.0.1.tar.gz.

File metadata

  • Download URL: levicanvas-1.0.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.8 Windows/10

File hashes

Hashes for levicanvas-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a78d4fd29a18f67fd55641bb67e09627593c92ed1e40f48a8ed941aea8bb79ec
MD5 28e17bd206f3bcce49666f05a46608c3
BLAKE2b-256 9592d2aee77fcb70b03628dae71c299f8c37c19e8f1abbec9877c4e5f1cccdba

See more details on using hashes here.

File details

Details for the file levicanvas-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: levicanvas-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.8 Windows/10

File hashes

Hashes for levicanvas-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 831e5ff042e0de11883b6067c597df9087d0f32bac16d02c5c3cf245cb566ca5
MD5 e166ca2f623eeeb4f8affc5093fdca27
BLAKE2b-256 6bd5fc919bc302a5aaaac6b84473714cc3157e3a9c553a68b61ab2d68409f991

See more details on using hashes here.

Supported by

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