Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rasterio to create webp #23

Open
vincentsarago opened this issue Mar 27, 2019 · 4 comments
Open

Use Rasterio to create webp #23

vincentsarago opened this issue Mar 27, 2019 · 4 comments

Comments

@vincentsarago
Copy link
Contributor

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

@dnomadb
Copy link
Contributor

dnomadb commented Mar 27, 2019

@vincentsarago I'm not seeing exactly how to create lossless webps -- is it is simple as setting lossless=True in the rasterio creation kwargs?

Also FWIW we should probably refactor this anyways as it was written before rasterio MemoryFiles were introduced.

with rasterio.open('/vsimem/tileimg', 'w', **profile) as dst:

Looking forward to the PR!

@vincentsarago
Copy link
Contributor Author

is it is simple as setting lossless=True in the rasterio creation kwargs?

I think yes, https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/profiles.py#L24-L27

Also FWIW we should probably refactor this anyways as it was written before rasterio MemoryFiles were introduced.

👌

Looking forward to the PR!

🤔 sure when you'll merge #18 :trollface:

@vincentsarago
Copy link
Contributor Author

vincentsarago commented Mar 30, 2019

I'll take care of this issue after #24 ;-)

@kylebarron
Copy link

@vincentsarago Now that #24 is merged, is this PR still valid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants