commit f2e109cf637e97fc8ecd606e7bd2150102f38724
parent b9f986f6d6a5cb4b999d19be9de3ffd0b7922214
Author: rob <rob@tarina.org>
Date: Wed, 12 Aug 2026 05:20:10 +0300
gif
Diffstat:
| M | server.py | | | 87 | ++++++++++++++++++++++++++++++++----------------------------------------------- |
1 file changed, 35 insertions(+), 52 deletions(-)
diff --git a/server.py b/server.py
@@ -719,6 +719,27 @@ def sendmail(email, subject, msg):
echomsg.wait()
#subprocess.call(['echo', msg, '|', 'mail', '-r', postadmin,'-s', subject, email])
+def get_new_frames(gif, scale):
+ new_frames = []
+ actual_frames = gif.n_frames
+ for frame in range(actual_frames):
+ gif.seek(frame)
+ new_frame = Image.new('RGBA', gif.size)
+ new_frame.paste(gif)
+ new_frame.thumbnail(scale, Image.Resampling.LANCZOS)
+ new_frames.append(new_frame)
+ return new_frames
+
+def save_new_gif(new_frames, old_gif_information, new_path):
+ new_frames[0].save(new_path,
+ save_all = True,
+ append_images = new_frames[1:],
+ duration = old_gif_information['duration'],
+ loop = old_gif_information['loop'],
+ background = old_gif_information['background'],
+ extension = old_gif_information['extension'] ,
+ transparency = old_gif_information['transparency'])
+
def resize_gif(input_path, output_path, max_size):
input_image = Image.open(input_path)
frames = list(_thumbnail_frames(input_image,max_size))
@@ -751,26 +772,6 @@ def scale_gif(path, scale, new_path=None):
new_frames = get_new_frames(gif, scale)
save_new_gif(new_frames, old_gif_information, new_path)
-def get_new_frames(gif, scale):
- new_frames = []
- actual_frames = gif.n_frames
- for frame in range(actual_frames):
- gif.seek(frame)
- new_frame = Image.new('RGBA', gif.size)
- new_frame.paste(gif)
- new_frame.thumbnail(scale, Image.Resampling.LANCZOS)
- new_frames.append(new_frame)
- return new_frames
-
-def save_new_gif(new_frames, old_gif_information, new_path):
- new_frames[0].save(new_path,
- save_all = True,
- append_images = new_frames[1:],
- duration = old_gif_information['duration'],
- loop = old_gif_information['loop'],
- background = old_gif_information['background'],
- extension = old_gif_information['extension'] ,
- transparency = old_gif_information['transparency'])
def getdisplayname(user):
try:
@@ -1555,38 +1556,6 @@ class rendered:
pass
return markdown.markdown(description+'\n\n---\n\n'+description2)
-def resize_gif(input_path, output_path, max_size):
- input_image = Image.open(input_path)
- frames = list(_thumbnail_frames(input_image,max_size))
- output_image = frames[0]
- output_image.save(
- output_path,
- save_all=True,
- append_images=frames[1:],
- disposal=input_image.disposal_method,
- **input_image.info,
- )
-
-def _thumbnail_frames(image,max_size):
- for frame in ImageSequence.Iterator(image):
- new_frame = frame.copy()
- new_frame.thumbnail(max_size, Image.Resampling.LANCZOS)
- yield new_frame
-
-def scale_gif(path, scale, new_path=None):
- gif = Image.open(path)
- if not new_path:
- new_path = path
- old_gif_information = {
- 'loop': bool(gif.info.get('loop', 1)),
- 'duration': gif.info.get('duration', 40),
- 'background': gif.info.get('background', 223),
- 'extension': gif.info.get('extension', (b'NETSCAPE2.0')),
- 'transparency': gif.info.get('transparency', 223)
- }
- new_frames = get_new_frames(gif, scale)
- save_new_gif(new_frames, old_gif_information, new_path)
-
def get_new_frames(gif, scale):
new_frames = []
actual_frames = gif.n_frames
@@ -1608,6 +1577,20 @@ def save_new_gif(new_frames, old_gif_information, new_path):
extension = old_gif_information['extension'] ,
transparency = old_gif_information['transparency'])
+def scale_gif(path, scale, new_path=None):
+ gif = Image.open(path)
+ if not new_path:
+ new_path = path
+ old_gif_information = {
+ 'loop': bool(gif.info.get('loop', 1)),
+ 'duration': gif.info.get('duration', 40),
+ 'background': gif.info.get('background', 223),
+ 'extension': gif.info.get('extension', (b'NETSCAPE2.0')),
+ 'transparency': gif.info.get('transparency', 223)
+ }
+ new_frames = get_new_frames(gif, scale)
+ save_new_gif(new_frames, old_gif_information, new_path)
+
def getallmedia(media_dir, extensions):
files = []
for ext in extensions: