forked from rDrama/rDrama
fdfd
parent
2eaf8effed
commit
f91fa3079c
|
@ -32,10 +32,11 @@ def crop_and_resize(img, resize):
|
|||
|
||||
def upload_file(file, resize=None):
|
||||
|
||||
if resize:
|
||||
filename = "image.gif"
|
||||
file.save(filename)
|
||||
i = IImage.open(filename)
|
||||
if resize: i = crop_and_resize(i, resize)
|
||||
i = crop_and_resize(i, resize)
|
||||
img = io.BytesIO()
|
||||
i.save(img, format='GIF')
|
||||
req = requests.post('https://api.imgur.com/3/upload.json', headers = {"Authorization": f"Client-ID {imgurkey}"}, data = {'image': base64.b64encode(img.getvalue())})
|
||||
|
@ -45,6 +46,13 @@ def upload_file(file, resize=None):
|
|||
print(req.text)
|
||||
return
|
||||
|
||||
else:
|
||||
req = requests.post('https://api.imgur.com/3/upload.json', headers = {"Authorization": f"Client-ID {imgurkey}"}, data = {'image': base64.b64encode(file.read())})
|
||||
try: resp = req.json()['data']
|
||||
except Exception as e:
|
||||
print(req.text)
|
||||
return
|
||||
|
||||
try: url = resp['link'].replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") + "?maxwidth=9999"
|
||||
except Exception as e:
|
||||
print(req.text)
|
||||
|
|
Loading…
Reference in New Issue