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

Improve repr of image bytes #902

Merged
merged 10 commits into from
Aug 2, 2022
Merged

Improve repr of image bytes #902

merged 10 commits into from
Aug 2, 2022

Conversation

banesullivan
Copy link
Contributor

When using getThumbnail() or getTile() in ipython/Jupyter, the bytes repr output can be overbearing and not all that useful as the image bytes can overtake the output with very long amounts of data.

These changes add a wrapper class to the bytes object for when we are returning PNG, JPEG, or TIFF image data (to give more user-friendly outputs in ipython and show an actual preview of the image in Jupyter

This is incredibly useful when trying to debug the graphical outputs of these methods.

master

In [1]: import large_image

In [2]: src = large_image.open('co_elevation.tif', projection='EPSG:3857')

In [3]: thumb, mime = src.getThumbnail()

In [4]: thumb
Out[4]: b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x02\x01\x01\x01\x01\x01\x02\x01\x01\x01\x02\x
... (really long bytes output)

This branch

In [1]: import large_image

In [2]: src = large_image.open('co_elevation.tif', projection='EPSG:3857')

In [3]: thumb, mime = src.getThumbnail()

In [4]: thumb
Out[4]: ImageBytes<16194> (image/jpeg)

Jupyter

master this branch
Screen Shot 2022-07-30 at 2 11 46 PM Screen Shot 2022-07-30 at 2 12 08 PM

Similarly works with getTile():

In [1]: import large_image

In [2]: src = large_image.open('co_elevation.tif',  encoding='PNG')

In [3]: tile = src.getTile(0,0,0)

In [4]: tile
Out[4]: ImageBytes<30086> (image/png)

In [5]:

Screen Shot 2022-07-30 at 2 13 25 PM

TIFF encodings simply repr out in Jupyter:
Screen Shot 2022-07-30 at 2 29 08 PM

@banesullivan banesullivan changed the title Improve repr of image bytes objects Improve repr of image bytes Jul 30, 2022
@banesullivan
Copy link
Contributor Author

Linting is failing due to flake8 5.0.0 release. See gforcada/flake8-isort#115

Other CI failures are due to a utf8 decoding error which I am also seeing on master. Not sure what's going on there.

@manthey
Copy link
Member

manthey commented Aug 1, 2022

This is great.

I think the other CI failure is because Glymur pushed a new version. Once that clears, if flake8-isort hasn't been updated, I'll pin it so CI passes.

@manthey
Copy link
Member

manthey commented Aug 1, 2022

If you rebase from or merge master, I think CI will pass (or at least be relevant).

@banesullivan
Copy link
Contributor Author

Oof, even more test failures coming from the converter

@manthey
Copy link
Member

manthey commented Aug 1, 2022

There was a type() check rather than an isinstance check.

@manthey
Copy link
Member

manthey commented Aug 1, 2022

The CI is still failing, but passes locally. I'll ssh in to circle to try to figure it out.

@manthey manthey merged commit 28e31b5 into master Aug 2, 2022
@manthey manthey deleted the image-bytes branch August 2, 2022 18:42
@banesullivan
Copy link
Contributor Author

Thank you for finalizing this, @manthey!

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

Successfully merging this pull request may close these issues.

2 participants