forked from rDrama/rDrama
fddf
parent
35bcf4c6bb
commit
2eaf8effed
|
@ -32,26 +32,18 @@ def crop_and_resize(img, resize):
|
|||
|
||||
def upload_file(file, resize=None):
|
||||
|
||||
if resize:
|
||||
filename = "image.gif"
|
||||
file.save(filename)
|
||||
i = IImage.open(filename)
|
||||
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())})
|
||||
remove(filename)
|
||||
try: resp = req.json()['data']
|
||||
except Exception as e:
|
||||
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
|
||||
filename = "image.gif"
|
||||
file.save(filename)
|
||||
i = IImage.open(filename)
|
||||
if 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())})
|
||||
remove(filename)
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue