Assume that the API that you work, like the AWS Rekognition, takes as input images in a byte format with a size limit. Thus, you may need to resize the image and then to convert it to a byte array. Let’s see how we can do it:
from PIL import Image import io photo = 'my_image.jpg' #open the image img = Image.open(photo, mode='r') # resize the image img = img.resize((300,300)) byteIO = io.BytesIO() img.save(byteIO, format='PNG') byteArr = byteIO.getvalue()