跳转到主要内容

一个基于Pillow、Wand和OpenCV的Python图像库

项目描述

Willow图像库

PyPI PyPI downloads Build Status

一个将多个Python图像库的功能结合到一个API中的包装器。

文档

概述

Willow是一个简单的图像库,结合了Pillow、Wand和OpenCV的API。在必要时,它会在库之间转换图像。

Willow目前具有基本的缩放和裁剪操作、人脸和特征检测以及动态GIF支持。新的操作和库集成也可以轻松实现

该库是用纯Python编写的,支持3.8、3.9、3.10、3.11和3.12版本。

示例

调整图像大小

from willow.image import Image

f = open('test.png', 'rb')
img = Image.open(f)

# Resize the image to 100x100 pixels
img = img.resize((100, 100))

# Save it
with open('test_thumbnail.png', 'wb') as out:
   img.save_as_png(out)

这将使用Pillow或Wand打开图像文件(如果Pillow不可用)。

然后将其调整到100x100像素,并保存为PNG文件。

检测人脸

from willow.image import Image

f = open('photo.png', 'rb')
img = Image.open(f)

# Find faces
faces = img.detect_faces()

如上所述,将使用Pillow或Wand加载图像文件。

由于Pillow和Wand都不支持检测人脸,Willow会自动将图像转换为OpenCV并使用它进行检测。

可用操作

文档

操作 Pillow Wand OpenCV
get_size()
get_frame_count() ✓** ✓**
resize(size)
crop(rect)
rotate(angle)
set_background_color_rgb(color)
transform_colorspace_to_srgb(rendering_intent)
auto_orient()
save_as_jpeg(file, quality)
save_as_png(file)
save_as_gif(file)
save_as_webp(file, quality)
save_as_heif(file, quality, lossless) ✓⁺
save_as_avif(file, quality, lossless) ✓⁺ ✓⁺
save_as_ico(file)
has_alpha() ✓*
has_animation() ✓* ✓*
get_pillow_image()
get_wand_image()
detect_features()
detect_faces(cascade_filename)

* 总是返回 False

** 总是返回 1

⁺ 需要 pillow-heif

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪一个,请了解更多关于 安装包 的信息。

源代码分发

willow-1.8.0.tar.gz (113.3 kB 查看哈希值)

上传时间 源代码

构建分发

willow-1.8.0-py3-none-any.whl (119.2 kB 查看哈希值)

上传时间 Python 3

由以下机构支持