Template tag for PIL image display
This commit is contained in:
parent
788ae99088
commit
b028ac3fc9
2 changed files with 14 additions and 0 deletions
0
common/templatetags/__init__.py
Normal file
0
common/templatetags/__init__.py
Normal file
14
common/templatetags/images.py
Normal file
14
common/templatetags/images.py
Normal 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}"
|
Loading…
Reference in a new issue