I am using autopy to take screenshots from my ubuntu desktop and publish to mqtt as a jpeg so I can view on home assistant via the mqtt camera entity. My solution works but I want to do the conversion on the fly without an intermediate file.
screen=autopy.bitmap.capture_screen()
screen.save("screenshot.jpeg")
with open("screenshot.jpeg", 'rb') as f:
filecontent = f.read()
byteArr = bytearray(filecontent)
client.publish(topic_screen, byteArr)
I would prefer to use autopy for the capture as I am using this to detect mouse movements in the same project.