-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
Add Support for webp format #6035
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #6035 +/- ##
===========================================
- Coverage 83.65% 39.11% -44.55%
===========================================
Files 305 305
Lines 45518 45519 +1
===========================================
- Hits 38079 17805 -20274
- Misses 7439 27714 +20275
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I have uploaded the tree here: https://assets.holoviz.org/panel/samples/webp_sample.webp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding support for webp! Looks good to me! Just some minor suggestions and if you can add a test similar to the other image tests!
Thanks for your comments I will just get to it 😄 |
hey, im struggling a bit to get the width and height to be set correctly in imgshp does anyone have any suggestions ? |
Hey @vaniisgh sorry for the late reply! My naive testing suggest it seems to be working. Can you elaborate on what the remaining issue is? ![]() |
panel/pane/image.py
Outdated
@classmethod | ||
def _imgshape(cls, data): | ||
import struct | ||
b = BytesIO(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use a context manager here:
with BytesIO(data) as b:
...
This seems to work for the sample image: import requests
response = requests.get("https://assets.holoviz.org/panel/samples/webp_sample.webp")
data = response.content
with open("webp_sample.webp", "wb") as f:
f.write(data)
def get_webp_dimensions(file_path):
with open(file_path, 'rb') as f:
header = f.read(30)
width = int.from_bytes(header[26:28], byteorder='little')
height = int.from_bytes(header[28:30], byteorder='little')
return width, height
get_webp_dimensions("webp_sample.webp") Returns: |
I think the issue only occurs in the test case ? Maybe the image I have created is incorrect... from base64 to webP. maybe I am not reading the header correctly, you seem to have done it a little different. let me just try it like your demonstration. while asserting the w,h. though I used the same image as the ones used in png, jpeg etc so I think that can't be the problem. |
Yes maybe the image might be incorrectly created; perhaps you can use another image if that's the case. |
Many thanks for your work on this @vaniisgh, really appreciated! |
Thanks, sorry for the long period of inactivity |
Think that was mostly on us tbh. |
Adding support to add webp files.
#5612