-
Notifications
You must be signed in to change notification settings - Fork 12
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
image not always resizing on cast #75
Comments
Adding a bit of debug log after figuring out how
That was the right dimensions, this one was not
|
It seems images are only scaled down and not scaled up. So what is the resolution of the input image? |
The images are collected from all over the place as my music collection grows, but that will probably explain it. Thanks. I did look at the source, but didn't quite understand it. |
I'm also in the process of 'rewriting' my entire Sonos media player page to include images. Actually took me quite some time before I realized that upscaling was not in the scope for push image 😆 Could be really nice if this could be implemented though, as online images for TuneIn Radiostations in the Sonos app. are only some 144x144 (appx.). My fix for now is to upscale these static appx. 8-10 images and store locally in flash. |
Is is possible from within the HA side (config/automations) to tell an image actual size either before or after conversion ? I'm having issues identifying all TuneIn's images, as some, but not all, of their URL's include an identifier. The no. 1 solution would of course be that push_image could do upscaling as well 😉🙋♂️ |
I think commenting these lines can achieve that: width = min(w for w in [width, original_width] if w is not None and w > 0)
height = min(h for h in [height, original_height] if h is not None and h > 0) |
@dgomes Can we allow up-scaling as well or is there a particular reason this is now allowed? |
only reason is that upscaling usually makes the image loose much quality |
I think that is the expected result when asking for a larger size of a small image... |
I agree. Even if user is not knowing the source image dimensions (quite common when doing something dynamic with media meta data), the desired end result is to have a fixed size image - No matter the quality. Currently I'm using templates in order to decide whether or not to zoom an image or not in my media player config. A tedious process, not dynamic at all and hardcoded into the templates. And I can only template 'known' repeated source images. Unknown source images from other family members Spotify accounts can result in the strangest images on the display. |
That works around the problem, but zoom adds the burden of scaling the image onto the ESP32. I think it is better to save these resources and let a PC do the scaling instead. |
Yep. Using zoom on large images, is clearly straining the mcu. Like local openHASP png converting is It would be a great overall enhancement, if CC could upscale images as well. |
Also much more needed now, as capable openHASP device screen resolution have increased quite a lot last six months. |
width = min(w for w in [width, original_width] if w is not None and w > 0)
height = min(h for h in [height, original_height] if h is not None and h > 0) Can you try commenting these two lines? My Python skills aren't advanced, but I think those two lines are limiting the upscaling. |
I actually believe i tried that back then, but not really sure. |
Also change the next line to: im.resize((height, width), Image.ANTIALIAS)
|
Tested that one as well - still a no go. |
replace min with max (but be careful not to send too large images) |
@fvanroie actually threw me this via Discord - and it's working 👍
Resizing with aspect ratios should still be dealt with though. |
Just tested and using this neither up- nor downscaling is working.
|
I updated the development branch with dc2d98b This adds a new a new optional argument "fit_screen" by which the image is resized to the "width" and "height" parameters regardless of the original file. |
Thank you @dgomes 🙂
No upscaling done, only downscaling.
Then it's working. Both supporting up- and downscaling. |
nice! |
For some odd reason |
This comment was marked as off-topic.
This comment was marked as off-topic.
That's a completely different issue, and none of the proposed configs can work (target is the domain of HA only, CC are restricted to |
Yep, sorry about that. Don't mix up issues 🤦♂️🙄 |
Confirmed new Unless I'm not really sure if that check is actually wanted ? |
Thumbnail assures aspect ratio, resize does not... The new option needs to be documented and eventually get a new name 😓 |
I don't know if a starting point could be just check the aspect ratio (AR = W / H) and if that is higher or equal to 1 then calculate height in reference to the width change ratio, If AR is less than one, then calculate width from height change ratio instead. Example - height calc from width change ratio: I don't know if it's really that simple or there are other 'traps' ? |
can be done but the point was to leave it up to the user to decide :) BTW: The legacy option (without fitscreen) assures correct aspect ratio |
Yep. I'm quite happy with current plain upscaling functionality. That saves me some tedious zoom templates 🙂👍 |
According to: https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio if not fitscreen:
width = min(w for w in [width, original_width] if w is not None and w > 0)
height = min(h for h in [height, original_height] if h is not None and h > 0)
im.thumbnail((width, height), Image.LANCZOS)
else:
wpercent = (width / float(original_width))
hsize = int((float(original_height) * float(wpercent)))
im = im.resize((width, hsize), Image.Resampling.LANCZOS) then only variable w is needed, when using fit screen. |
With the recent update to the image resizing to fitscreen=1 to fix a problem I was facing (the source image changes size often and the same image is converted for multiple displays), I implemented the ImageOps from PIL (which was used for Image anyway) which does a aspect ratio preserving resize without using thumbnail and does size up if required to get to the size you set it to. This change only kicks in when fitscreen=1, if that is not set at all or to 0 it will still use the thumbnail function. Maybe we need to implement ImageOps in the other use case too... |
Version of the custom_component
0.63
Configuration
The text was updated successfully, but these errors were encountered: