Now I want to encode part image in base64 and I did do it. For example, here is an image 1080x1920, but part of this image is needed.
Top:160, left:340, right:1024, bottom:650.
# first crop
im = Image.open(original)
region = im.crop((160, 340, 1024, 650))
clip_image = os.path.join(screenshot_dir, 'clip.png')
region.save(clip_image)
// then read
f = open(clip_image, 'rb')
ls_f = base64.b64encode(f.read())
f.close()
s = bytes.decode(ls_f)
In my opinion, maybe I do not have to save resized image and I can read part of this image directly. If so, the program can run faster because there is no extra IO
operation.