diff --git a/common/templatetags/__init__.py b/common/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/common/templatetags/images.py b/common/templatetags/images.py new file mode 100644 index 0000000..94bcd68 --- /dev/null +++ b/common/templatetags/images.py @@ -0,0 +1,14 @@ +from django import template + +from io import BytesIO + +import base64 + +register = template.Library() + +@register.simple_tag +def pildata(image): + data = BytesIO() + image.save(data, "JPEG") + content = base64.b64encode(data.getvalue()).decode("UTF-8") + return f"data:img/jpeg;base64,{content}" \ No newline at end of file