anibali / pywebp

Python bindings for WebP
MIT License
74 stars 24 forks source link

Support raw numpy arrays #5

Closed TadLeonard closed 5 years ago

TadLeonard commented 5 years ago

In my typical workflow, Pillow really offers nothing valuable to me. I keep my code in the NumPy/OpenCV world, and the PIL abstraction of images just isn't useful there. NumPy itself is actually a pretty great tool for doing a lot of common image processing tasks.

For that reason, it'd be pretty cool if webp supported NumPy arrays in save_image, save_images, and elsewhere. It shouldn't be terribly complicated to add this. It seems like webp needs a pointer to the raw, underlying data. You can definitely get that from a NumPy array. You also need width and height, which you can get from array.shape[:2].

Great project! The code itself looks super clean. Nice to see Enum getting used. Can't wait to replace imageio with webp in certain cases!

anibali commented 5 years ago

Thanks for the kind words. I've added numpy-friendly functions in PR https://github.com/anibali/pywebp/pull/6 and released 0.1.0a11 to PyPI with the changes. You can now use the new imread, imwrite, mimread, and mimwrite functions with numpy arrays, similarly to how you would in imageio.