Skip to content
Advertisement

How to decrease Image object size that dumped through pickle in Python

I’m working on a socket data transfer project. I want to watch client screen. I’m using pillow and pickle module both server and client but when I trying to send ImageGrab.grab() object, object size is 3Mb. It’s very high data for transferring. Although object size is 3MB, saved size (ImageGrab.grab().save(“example.jpg”)) is 200 kb. When i save file then read saved photo for transferring, it cause very high cpu usage. Even i try to send bytes of object -> ImageGrab.grab().tobytes() <- , its again 3mb. How can i send only data of image from object without saving file ?

Advertisement

Answer

I solved this problem through IO

from PIL import Image, ImageGrab
a = ImageGrab.grab()
import io
b = io.BytesIO()
a.save(b, "JPEG")
len(b.getbuffer())
224455
Advertisement