Template tag for PIL image display

This commit is contained in:
Kumi 2021-02-20 13:39:54 +00:00
parent 837d0313ca
commit 67d303f9f9
2 changed files with 14 additions and 0 deletions

View file

View file

@ -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}"