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