summaryrefslogtreecommitdiff
path: root/odoo/addons/base/tests
diff options
context:
space:
mode:
authorChristophe Monniez <moc@odoo.com>2021-02-05 16:55:21 +0000
committerChristophe Monniez <moc@odoo.com>2021-02-09 11:32:23 +0000
commitbfd3f857b44f31f8077182d10cab869f42076464 (patch)
treea9fe3dd94bb970ec25a3246b2f412e91603571e3 /odoo/addons/base/tests
parent550906d48682996cb47142bb0d519fdbfac69642 (diff)
[FIX] tools: prevent call to pillow exif_transpose image method
In a previous fix [0], the call to exif_transpose was kept to allow rotation of images format different than `JPEG`. After a small test, it appeared that the call would crash if the image in another format had the same `LensInfo` tag. So it's safer to not call this method at all. With this commit, the rotation tag is retrieved disregarding the file format by using the `getexif` method if available, falling back to the private method for Pillow < 6 support. As a bonus, a test is also added with a small embedded `JPEG` image, crafted with an `Orientation` exif tag and, for reference, the `LensInfo`tag that caused so much trouble. The fix referenced in [0] was not forward-ported as it was only moving the code the is completely removed in the present. [0] b83c48d5c48954193 closes odoo/odoo#65793 X-original-commit: 38f696dfa5134d93b5a3a1c0647aa8f8c1bd18c9 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Diffstat (limited to 'odoo/addons/base/tests')
-rw-r--r--odoo/addons/base/tests/test_image.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/odoo/addons/base/tests/test_image.py b/odoo/addons/base/tests/test_image.py
index 2d4c3940b8d..1966ece06f1 100644
--- a/odoo/addons/base/tests/test_image.py
+++ b/odoo/addons/base/tests/test_image.py
@@ -21,6 +21,23 @@ class TestImage(TransactionCase):
self.base64_1x1_png = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC'
self.base64_svg = base64.b64encode(b'<svg></svg>')
self.base64_1920x1080_jpeg = tools.image_to_base64(Image.new('RGB', (1920, 1080)), 'JPEG')
+ # The following image contains a tag `Lens Info` with a value of `3.99mm f/1.8`
+ # This particular tag 0xa432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Z2hpanN0
+ dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX
+ 2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigD//2Q=="""
# Draw a red square in the middle of the image, this will be used to
# verify crop is working. The border is going to be `self.bg_color` and
@@ -91,6 +108,13 @@ class TestImage(TransactionCase):
self._orientation_test(7, (pink, yellow, green, blue), size, expected) # right/bottom
self._orientation_test(8, (green, blue, pink, yellow), size, expected) # left/bottom
+ def test_03_image_fix_orientation_exif(self):
+ """Test that a jpg image with exif orientation tag gets rotated"""
+ image = tools.base64_to_image(self.base64_exif_jpg)
+ self.assertEqual(image.size, (6,3))
+ image = tools.image_fix_orientation(image)
+ self.assertEqual(image.size, (3,6))
+
def test_10_image_process_base64_source(self):
"""Test the base64_source parameter of image_process."""
wrong_base64 = b'oazdazpodazdpok'