in
|
def _encode_as_webp(data, profile=None, affine=None): |
|
""" |
|
Uses BytesIO + PIL to encode a (3, 512, 512) |
|
array into a webp bytearray. |
|
|
|
Parameters |
|
----------- |
|
data: ndarray |
|
(3 x 512 x 512) uint8 RGB array |
|
profile: None |
|
ignored |
|
affine: None |
|
ignored |
|
|
|
Returns |
|
-------- |
|
contents: bytearray |
|
webp-encoded bytearray of the provided input data |
|
""" |
|
with BytesIO() as f: |
|
im = Image.fromarray(np.rollaxis(data, 0, 3)) |
|
im.save(f, format='webp', lossless=True) |
|
|
|
return f.getvalue() |
we use Pillow to save the image as webp. Since rasterio ~1.0.9 , rasterio wheels are shipped with Webp driver so we could use rasterio instead of PIL and save on the dependency ;-)
cc @dnomadb
in
rio-rgbify/rio_rgbify/mbtiler.py
Lines 46 to 69 in 31bd65b
cc @dnomadb