fix: made requested changes

This commit is contained in:
Abhishek Balam 2020-11-30 18:58:53 +05:30
parent 8f8489d9b3
commit e306f5601c
5 changed files with 28 additions and 28 deletions

View file

@ -470,11 +470,14 @@ class File(Document):
self.content_type = mimetypes.guess_type(self.file_name)[0]
if self.content_type and "image" in self.content_type and \
frappe.get_system_settings("remove_exif_tags"):
self.file_size = self.check_max_file_size()
if (
self.content_type and "image" in self.content_type
and frappe.get_system_settings("strip_exif_metadata_from_uploaded_images")
):
self.content = strip_exif_data(self.content, self.content_type)
self.file_size = self.check_max_file_size()
self.content_hash = get_content_hash(self.content)
duplicate_file = None

View file

@ -37,7 +37,7 @@
"allow_login_using_mobile_number",
"allow_login_using_user_name",
"allow_error_traceback",
"remove_exif_tags",
"strip_exif_metadata_from_uploaded_images",
"password_settings",
"logout_on_password_reset",
"force_user_to_reset_password",
@ -464,15 +464,15 @@
},
{
"default": "1",
"fieldname": "remove_exif_tags",
"fieldname": "strip_exif_metadata_from_uploaded_images",
"fieldtype": "Check",
"label": "Remove EXIF tags from uploaded images"
"label": "Strip EXIF tags from uploaded images"
}
],
"icon": "fa fa-cog",
"issingle": 1,
"links": [],
"modified": "2020-11-30 17:04:06.785282",
"modified": "2020-11-30 18:52:22.161391",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",

View file

@ -1,19 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import unittest
from PIL import Image
from frappe.utils.image import strip_exif_data
import io
class TestImage(unittest.TestCase):
def test_strip_exif_data(self):
original_image = Image.open("../apps/frappe/frappe/tests/data/exif_sample_image.jpg")
original_image_content = io.open("../apps/frappe/frappe/tests/data/exif_sample_image.jpg", mode='rb').read()
new_image_content = strip_exif_data(original_image_content, "image/jpeg")
new_image = Image.open(io.BytesIO(new_image_content))
self.assertEqual(new_image._getexif(), None)
self.assertNotEqual(original_image._getexif(), new_image._getexif())

View file

@ -7,6 +7,10 @@ import unittest
from frappe.utils import evaluate_filters, money_in_words, scrub_urls, get_url
from frappe.utils import ceil, floor
from PIL import Image
from frappe.utils.image import strip_exif_data
import io
class TestFilters(unittest.TestCase):
def test_simple_dict(self):
self.assertTrue(evaluate_filters({'doctype': 'User', 'status': 'Open'}, {'status': 'Open'}))
@ -122,3 +126,14 @@ class TestHTMLUtils(unittest.TestCase):
clean = clean_email_html(sample)
self.assertTrue('<h1>Hello</h1>' in clean)
self.assertTrue('<a href="http://test.com">text</a>' in clean)
class TestImage(unittest.TestCase):
def test_strip_exif_data(self):
original_image = Image.open("../apps/frappe/frappe/tests/data/exif_sample_image.jpg")
original_image_content = io.open("../apps/frappe/frappe/tests/data/exif_sample_image.jpg", mode='rb').read()
new_image_content = strip_exif_data(original_image_content, "image/jpeg")
new_image = Image.open(io.BytesIO(new_image_content))
self.assertEqual(new_image._getexif(), None)
self.assertNotEqual(original_image._getexif(), new_image._getexif())

View file

@ -19,12 +19,13 @@ def resize_images(path, maxdim=700):
print("resized {0}".format(os.path.join(basepath, fname)))
def strip_exif_data(content, content_type):
""" Strips exif from image files which support it.
""" Strips EXIF from image files which support it.
Works by creating a new Image object which ignores exif by
default and then extracts the binary data back into content.
Returns: stripped image content
Returns:
Bytes: Stripped image content
"""
from PIL import Image