diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index a720b404f0..2257ac8d49 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -112,7 +112,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" {% elif df.fieldtype in ("Attach", "Attach Image") and doc[df.fieldname] - and (guess_mimetype(doc[df.fieldname])[0] or "").startswith("image/") %} + and frappe.utils.is_image(doc[df.fieldname]) %} {% elif df.fieldtype=="HTML" %} diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 9eb5140b24..6bf0cb8880 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -516,6 +516,13 @@ def is_html(text): break return out +def is_image(filepath): + from mimetypes import guess_type + + # filepath can be https://example.com/bed.jpg?v=129 + filepath = filepath.split('?')[0] + return (guess_type(filepath)[0] or "").startswith("image/") + # from Jinja2 code _striptags_re = re.compile(r'(|<[^>]*>)')