Answer the question
In order to leave comments, you need to log in
How to convert PIL object to Bytes?
image_content = requests.get(image_url).content
image = Image.open(BytesIO(image_content))
image = image.crop((0, 0, image.size[0], image.size[0]*0.975))
image_content = BytesIO()
image.save(image_content, format='JPEG')
requests.post(url, files={'photo': ('upload.jpg', image_content)})
image_content = BytesIO()
image.save(image_content, format='JPEG')
Answer the question
In order to leave comments, you need to log in
from PIL import Image
import requests
from io import BytesIO
response = requests.get(url)
img = Image.open(BytesIO(response.content))
with open(filename, 'rb') as f:
r = requests.post(url, data=f.read())
Summarizing the long correspondence in the comments to the previous answer, it turns out something like this:
image_content = requests.get(image_url).content
image = Image.open(BytesIO(image_content))
image = image.crop((0, 0, image.size[0], image.size[0]*0.975))
image_content = BytesIO()
image.seek(0)
image.save(image_content, format='JPEG')
image_content.seek(0)
requests.post(url, files={'photo': ('upload.jpg', image_content)})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question