forked from rDrama/rDrama
master
parent
c373fa580d
commit
1cb9d911e7
|
@ -1,6 +1,6 @@
|
||||||
import requests
|
import requests
|
||||||
from os import environ, path, remove
|
from os import environ, path, remove
|
||||||
from PIL import Image, ImageSequence
|
from PIL import Image as IImage, ImageSequence
|
||||||
import base64
|
import base64
|
||||||
from files.classes.images import *
|
from files.classes.images import *
|
||||||
from flask import g
|
from flask import g
|
||||||
|
@ -16,14 +16,14 @@ def upload_ibb(file=None, resize=False):
|
||||||
if file: file.save("image.webp")
|
if file: file.save("image.webp")
|
||||||
|
|
||||||
if resize:
|
if resize:
|
||||||
i = Image.open("image.webp")
|
i = IImage.open("image.webp")
|
||||||
size = 100, 100
|
size = 100, 100
|
||||||
frames = ImageSequence.Iterator(i)
|
frames = ImageSequence.Iterator(i)
|
||||||
|
|
||||||
def thumbnails(frames):
|
def thumbnails(frames):
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
thumbnail = frame.copy()
|
thumbnail = frame.copy()
|
||||||
thumbnail.thumbnail(size, Image.ANTIALIAS)
|
thumbnail.thumbnail(size, IImage.ANTIALIAS)
|
||||||
yield thumbnail
|
yield thumbnail
|
||||||
|
|
||||||
frames = thumbnails(frames)
|
frames = thumbnails(frames)
|
||||||
|
@ -40,13 +40,13 @@ def upload_ibb(file=None, resize=False):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sequence = []
|
sequence = []
|
||||||
im = Image.open("image.webp")
|
im = IImage.open("image.webp")
|
||||||
for frame in ImageSequence.Iterator(im):
|
for frame in ImageSequence.Iterator(im):
|
||||||
sequence.append(frame.copy())
|
sequence.append(frame.copy())
|
||||||
|
|
||||||
sequence[0].save("image.webp", save_all=True, append_images = sequence[1:])
|
sequence[0].save("image.webp", save_all=True, append_images = sequence[1:])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,14 +79,14 @@ def upload_imgur(filepath=None, file=None, resize=False):
|
||||||
else: format = filepath.split('.')[-1].lower().replace('jpg','png').replace('jpeg','png')
|
else: format = filepath.split('.')[-1].lower().replace('jpg','png').replace('jpeg','png')
|
||||||
|
|
||||||
if resize:
|
if resize:
|
||||||
i = Image.open(filepath)
|
i = IImage.open(filepath)
|
||||||
size = 100, 100
|
size = 100, 100
|
||||||
frames = ImageSequence.Iterator(i)
|
frames = ImageSequence.Iterator(i)
|
||||||
|
|
||||||
def thumbnails(frames):
|
def thumbnails(frames):
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
thumbnail = frame.copy()
|
thumbnail = frame.copy()
|
||||||
thumbnail.thumbnail(size, Image.ANTIALIAS)
|
thumbnail.thumbnail(size, IImage.ANTIALIAS)
|
||||||
yield thumbnail
|
yield thumbnail
|
||||||
|
|
||||||
frames = thumbnails(frames)
|
frames = thumbnails(frames)
|
||||||
|
@ -99,7 +99,7 @@ def upload_imgur(filepath=None, file=None, resize=False):
|
||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
elif format != "gif":
|
elif format != "gif":
|
||||||
i = Image.open(filepath)
|
i = IImage.open(filepath)
|
||||||
filepath = f"image.{i.format}".lower().replace('jpg','png').replace('jpeg','png')
|
filepath = f"image.{i.format}".lower().replace('jpg','png').replace('jpeg','png')
|
||||||
i.save(filepath, optimize=True, quality=30)
|
i.save(filepath, optimize=True, quality=30)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue