fd
This commit is contained in:
parent
f7ee3c4bdb
commit
9d18a889dc
1 changed files with 12 additions and 12 deletions
|
@ -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)
|
||||||
|
@ -42,7 +42,7 @@ 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())
|
||||||
|
|
||||||
|
@ -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…
Add table
Add a link
Reference in a new issue