fd
This commit is contained in:
parent
b2ec0f4920
commit
d9fe413583
1 changed files with 3 additions and 12 deletions
|
@ -34,14 +34,12 @@ def upload_ibb(filepath=None, file=None, resize=False):
|
||||||
|
|
||||||
om = next(frames)
|
om = next(frames)
|
||||||
om.info = i.info
|
om.info = i.info
|
||||||
filepath = f"image.{i.format}"
|
|
||||||
try: om.save(filepath, save_all=True, append_images=list(frames), loop=0, optimize=True, quality=30)
|
try: om.save(filepath, save_all=True, append_images=list(frames), loop=0, optimize=True, quality=30)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
elif format != "gif":
|
elif format != "gif":
|
||||||
i = IImage.open(filepath)
|
i = IImage.open(filepath)
|
||||||
filepath = f"image.{i.format}"
|
|
||||||
i.save(filepath, optimize=True, quality=30)
|
i.save(filepath, optimize=True, quality=30)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -68,32 +66,25 @@ def upload_imgur(filepath=None, file=None, resize=False):
|
||||||
|
|
||||||
if resize:
|
if resize:
|
||||||
i = IImage.open(filepath)
|
i = IImage.open(filepath)
|
||||||
format = i.format
|
|
||||||
i = IImage.open(filepath).convert("RGBA")
|
|
||||||
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:
|
||||||
new_image = IImage.new("RGBA", frame.size, "WHITE")
|
thumbnail = frame.copy()
|
||||||
new_image.paste(frame, mask=frame)
|
thumbnail.thumbnail(size, IImage.ANTIALIAS)
|
||||||
new_image.convert("RGB")
|
yield thumbnail
|
||||||
new_image.thumbnail(size)
|
|
||||||
yield new_image
|
|
||||||
|
|
||||||
frames = thumbnails(frames)
|
frames = thumbnails(frames)
|
||||||
|
|
||||||
om = next(frames)
|
om = next(frames)
|
||||||
om.info = i.info
|
om.info = i.info
|
||||||
filepath = f"image.{format}"
|
|
||||||
try: om.save(filepath, save_all=True, append_images=list(frames), loop=0, optimize=True, quality=30)
|
try: om.save(filepath, save_all=True, append_images=list(frames), loop=0, optimize=True, quality=30)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
elif format != "gif":
|
elif format != "gif":
|
||||||
i = IImage.open(filepath)
|
i = IImage.open(filepath)
|
||||||
filepath = f"image.{i.format}"
|
|
||||||
i.save(filepath, optimize=True, quality=30)
|
i.save(filepath, optimize=True, quality=30)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue