fd
This commit is contained in:
parent
ccc9187711
commit
9fa6fca589
5 changed files with 62 additions and 10 deletions
|
@ -8,9 +8,46 @@ from flask import g
|
|||
CF_KEY = environ.get("CLOUDFLARE_KEY", "").strip()
|
||||
CF_ZONE = environ.get("CLOUDFLARE_ZONE", "").strip()
|
||||
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
||||
IBB_KEY = environ.get("IBB_KEY", "").strip()
|
||||
|
||||
def upload_ibb(file=None, resize=False, png=False):
|
||||
|
||||
if file: file.save("image.gif")
|
||||
|
||||
if resize:
|
||||
i = IImage.open("image.gif")
|
||||
size = 100, 100
|
||||
frames = ImageSequence.Iterator(i)
|
||||
|
||||
def thumbnails(frames):
|
||||
for frame in frames:
|
||||
thumbnail = frame.copy()
|
||||
thumbnail.thumbnail(size, IImage.ANTIALIAS)
|
||||
yield thumbnail
|
||||
|
||||
frames = thumbnails(frames)
|
||||
|
||||
om = next(frames)
|
||||
om.info = i.info
|
||||
try: om.save("image.gif", save_all=True, append_images=list(frames), loop=0)
|
||||
except: return
|
||||
|
||||
if png: filedir = "image.png"
|
||||
else: filedir = "image.gif"
|
||||
try:
|
||||
with open(filedir, 'rb') as f:
|
||||
data={'image': base64.b64encode(f.read())}
|
||||
req = requests.post(f'https://api.imgbb.com/1/upload?key={IBB_KEY}', data=data)
|
||||
resp = req.json()['data']
|
||||
url = resp['url']
|
||||
except:
|
||||
if req: print(req.json())
|
||||
return
|
||||
|
||||
return(url)
|
||||
|
||||
|
||||
def upload_file(file=None, resize=False, png=False):
|
||||
def upload_imgur(file=None, resize=False, png=False):
|
||||
|
||||
if file: file.save("image.gif")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue