.
This commit is contained in:
+1
-16
@@ -58,22 +58,7 @@ import json
|
|||||||
import statistics
|
import statistics
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
|
|
||||||
|
from helpers.images import image_as_base64
|
||||||
def image_as_base64(image_file):
|
|
||||||
"""
|
|
||||||
:param `image_file` for the complete path of image.
|
|
||||||
:param `format` is format for image, eg: `png` or `jpg`.
|
|
||||||
"""
|
|
||||||
# if not os.path.isfile(image_file):
|
|
||||||
# return None
|
|
||||||
|
|
||||||
encoded_string = ""
|
|
||||||
# with open(image_file, 'rb') as img_f:
|
|
||||||
# encoded_string = base64.b64encode(img_f.read())
|
|
||||||
encoded_string = base64.b64encode(image_file.file.read())
|
|
||||||
mimetype, enc = mimetypes.guess_type(image_file.path)
|
|
||||||
return "data:image/{};base64,{}".format(mimetype, encoded_string.decode("utf-8"))
|
|
||||||
|
|
||||||
|
|
||||||
from django.template.defaulttags import register
|
from django.template.defaulttags import register
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
def image_as_base64(image_file):
|
||||||
|
"""
|
||||||
|
:param `image_file` for the complete path of image.
|
||||||
|
:param `format` is format for image, eg: `png` or `jpg`.
|
||||||
|
"""
|
||||||
|
# if not os.path.isfile(image_file):
|
||||||
|
# return None
|
||||||
|
|
||||||
|
encoded_string = ""
|
||||||
|
# with open(image_file, 'rb') as img_f:
|
||||||
|
# encoded_string = base64.b64encode(img_f.read())
|
||||||
|
encoded_string = base64.b64encode(image_file.file.read())
|
||||||
|
mimetype, enc = mimetypes.guess_type(image_file.path)
|
||||||
|
return "data:image/{};base64,{}".format(mimetype, encoded_string.decode("utf-8"))
|
||||||
@@ -49,6 +49,8 @@ from collections import defaultdict
|
|||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
from helpers.images import image_as_base64
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
|
|||||||
Reference in New Issue
Block a user