mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-08-30 18:57:10 +00:00
[AB-70] moving image generation functionality to separate image generation module
removing doge image generation from default base split rest-api into separate modules (base and extensions)
This commit is contained in:
24
python/components/rest-api-base/python/utils/flask_utils.py
Normal file
24
python/components/rest-api-base/python/utils/flask_utils.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from io import BytesIO
|
||||
|
||||
from flask import send_file
|
||||
|
||||
|
||||
def serve_pil_image(pil_img):
|
||||
img_io = BytesIO()
|
||||
pil_img.save(img_io, 'PNG')
|
||||
img_io.seek(0)
|
||||
return send_file(img_io, mimetype='image/png')
|
||||
|
||||
|
||||
def serve_pil_gif_image(frames, duration=25):
|
||||
animated_gif = BytesIO()
|
||||
frames[0].save(animated_gif, format='GIF', save_all=True, append_images=frames[1:], duration=duration, loop=0, disposal=2)
|
||||
animated_gif.seek(0)
|
||||
return send_file(animated_gif, mimetype='image/gif')
|
||||
|
||||
|
||||
class ValidationException(Exception):
|
||||
def __init__(self, provided_value, message):
|
||||
self.provided_value = provided_value
|
||||
self.message = message
|
||||
super().__init__(f'{self.message}: provided value: {provided_value}')
|
||||
Reference in New Issue
Block a user