From ea673addf53df27796d63a6539fb89b4ee9b5ef2 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Date: Mon, 13 Nov 2023 14:10:54 -0300 Subject: [PATCH] add clear image metadata option --- README.md | 2 ++ remotecv/image.py | 20 +++++++++++++++++++- remotecv/worker.py | 9 +++++++++ tests/fixtures/with_metadata.tiff | Bin 0 -> 6062 bytes tests/test_images.py | 17 +++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/with_metadata.tiff diff --git a/README.md b/README.md index 0145a42..ac39aeb 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ Options: --sentry-url TEXT Sentry URL [env var: SENTRY_URL] --metrics TEXT Metrics client, should be the full name of a python module [env var: METRICS_CLIENT] + --clear-image-metadata Clears metadata when loading image + [env var: CLEAR_IMAGE_METADATA] Memcached store arguments: --memcached-hosts TEXT Comma separated list of memcached hosts [env var: MEMCACHED_HOSTS] diff --git a/remotecv/image.py b/remotecv/image.py index 1677f78..5eae807 100644 --- a/remotecv/image.py +++ b/remotecv/image.py @@ -2,6 +2,8 @@ from PIL import Image as PilImage +from remotecv.utils import config + PilImage.IGNORE_DECODING_ERRORS = True PilImage.MAXBLOCK = 2**25 @@ -23,4 +25,20 @@ def parse_image(self, image_buffer): img.load() except IOError: pass - return img + + return self.clear_metadata(img) + + def clear_metadata(self, image): + if ( + not hasattr(config, "clear_image_metadata") + or not config.clear_image_metadata + ): + return image + + if hasattr(image, "tag"): + image.tag.clear() + + if hasattr(image, "tag_v2"): + image.tag_v2.clear() + + return image diff --git a/remotecv/worker.py b/remotecv/worker.py index a1887d0..36f0dde 100644 --- a/remotecv/worker.py +++ b/remotecv/worker.py @@ -297,6 +297,14 @@ def import_modules(): default="remotecv.metrics.logger_metrics", help="Metrics client, should be the full name of a python module", ) +@optgroup.option( + "--clear-image-metadata", + envvar="CLEAR_IMAGE_METADATA", + show_envvar=True, + is_flag=True, + default=False, + help="Clears metadata when loading image", +) @optgroup.group("Memcached store arguments") @optgroup.option( "--memcached-hosts", @@ -335,6 +343,7 @@ def main(**params): config.timeout = params["timeout"] config.worker_ttl = params["worker_ttl"] config.prune_dead_members = params["prune_dead_members"] + config.clear_image_metadata = params["clear_image_metadata"] config.server_port = params["server_port"] config.log_level = params["level"].upper() config.loader = import_module(params["loader"]) diff --git a/tests/fixtures/with_metadata.tiff b/tests/fixtures/with_metadata.tiff new file mode 100644 index 0000000000000000000000000000000000000000..b85ccab889905b647db0df2e22d77ed2e62f77e7 GIT binary patch literal 6062 zcmbVQ2S60p)*fttNUzcbF(_aI3-%bhNz|Z*7^B9nu|#9k7h{QF4hY#;SI1mKkL=bk(2s@m$ z$B*5cd1stAv1>{+#s9bCrzy_md*n}xH}fVqcYkw#4$i&b{4PJ^^UgZHZ{}{k1QGbo zIv0}ci57ToI)3EK!TK+@YnRwAT}25{B&*0XSp<~V&z=bsrLC{G==BoAv82VI(Sjh- z7RqEWQf8L12(*z`yi_wLi7^Sl0SEvResE@%z#xJ~0KN4q{N?p`(1@<6eg&dPnMi?R zbm~TsK&hxR8gu|6&vN*+L7@f_NS(!~A%TAvnv%dIf=&P<$bb0j%ck!iwU%`!jV2VM zR%g_kfJ37|?Q4a=@jPcy)V-o;Bg_;*2+Reqy2BY{N%QUvq=6DI}2v2~C04Mm2G- zEQ%-BD{BG%v}~YT+cBgUM58 z1%`&(JGnT!d$e+P4GwAJ<>lq$=k4T-=uRPFzFz*Vk~Xd2a-!N1!EOA4!hJa~ z^FWI>gTIBA)9vr|7UV4c6SSO}tcYXb!6SrS6IXXPl}h=#=7p!bN5aSno!Z6o7`eEt z2uMo4t$jSb-EQ2yj=4=Sq`Y5A;273oFpH?e{|XvVYgtotF+fdyqgrR&_+v^d7pL7B zJ1~-YMz2xS#74wzSe^nDz=$TB$oKcG=3 zqlMbFE3HLy;#zr0e)cvWR{~h0PZOsf=6;vGWw!%iziP?qthDTw4$duFI3%yzV4*2N z5;=iIXgSLSmZ8xIe;?$s!R4ruGwZF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