I’ve been looking into this again and keep going around in circles… looking at github and the python script for the camera proxy is almost what I need but wont quite cut it. Its slightly above my skill levels to modify the code to do what I want, hence asking for help again.
I have 2 types of camera with slightly different aspect ratios 1.6:1 and 1.3:1, neither of which are in a 2:1 ratio as android notifications display and hence are cropped and I lose the top and bottom of the image.
basically what I would like to do is pad the sides of the image so I can see the full height. I’m considering using camera proxy as a starting point, I came up with the following function to add to the camera proxy (completely untested)
def _pad_2to1ratio(image, opts):
"""Pad image to 2:1 ratio"""
img = _precheck_image(image, opts)
quality = opts.quality or DEFAULT_QUALITY
(old_width, old_height) = img.size
old_size = len(image)
if old_width == (2 * old_height):
elif old_width > (2 * old_height):
result = Image.new(img.mode, (old_width, old_width // 2), (0, 0, 0))
result.paste(img, (0, (old_width - old_height) // 2))
result = Image.new(img.mode, (old_height * 2, old_height), (0, 0, 0))
result.paste(img, ((old_height * 2 - old_width) // 2, 0))
imgbuf = io.BytesIO()
img.save(imgbuf, "JPEG", optimize=True, quality=quality)
newimage = imgbuf.getvalue()
(new_width, new_height) = newimage.size
"Padded image from (%dx%d - %d bytes) to (%dx%d - %d bytes)",
ultimately I think this could be a valuable addition to camera proxy, and it would be nice to pass is in the padding color and custom ratio’s, but for now this should do…
I only have a live home assistant setup and don’t want to break it… so what’s the best way to test and debug this? I’m not even sure where camera.py lives in HA