Cropped image android notification using camera proxy

Hi, I have setup notifications for my cameras around my house
I use the line

image: /api/camera_proxy/camera.{{ trigger.entity_id.split('.')[-1] }}_snap

to take the image thats sent via mqtt and pass it to the notification.

the notification is very cropped, with about 25% of the top missing, and 25% of the bottom missing.

Is there a way to change this behaviour or pass a max height parameter without having to create a proxy for each camera?

This is an Android thing. You’ll need to resize the image to be 2:1 to fit properly in the notification.

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)
    except ValueError:
        return image

    quality = opts.quality or DEFAULT_QUALITY

    (old_width, old_height) = img.size
	old_size = len(image)
    if old_width == (2 * old_height):
        return image
    elif old_width > (2 * old_height):
        result =, (old_width, old_width // 2), (0, 0, 0))
        result.paste(img, (0, (old_width - old_height) // 2))

        result =, (old_height * 2, old_height), (0, 0, 0))
        result.paste(img, ((old_height * 2 - old_width) // 2, 0))

    imgbuf = io.BytesIO(), "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)",
    return newimage

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 lives in HA

This is way too complicated for me… can someone help with a method to resize/pad the image to the correct ratio?