File tree Expand file tree Collapse file tree 5 files changed +47
-1
lines changed Expand file tree Collapse file tree 5 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,8 @@ Options:
118
118
--sentry-url TEXT Sentry URL [env var: SENTRY_URL]
119
119
--metrics TEXT Metrics client, should be the full name of a
120
120
python module [env var: METRICS_CLIENT]
121
+ --clear-image-metadata Clears metadata when loading image
122
+ [env var: CLEAR_IMAGE_METADATA]
121
123
Memcached store arguments:
122
124
--memcached-hosts TEXT Comma separated list of memcached hosts
123
125
[env var: MEMCACHED_HOSTS]
Original file line number Diff line number Diff line change 2
2
3
3
from PIL import Image as PilImage
4
4
5
+ from remotecv .utils import config
6
+
5
7
PilImage .IGNORE_DECODING_ERRORS = True
6
8
PilImage .MAXBLOCK = 2 ** 25
7
9
@@ -23,4 +25,20 @@ def parse_image(self, image_buffer):
23
25
img .load ()
24
26
except IOError :
25
27
pass
26
- return img
28
+
29
+ return self .clear_metadata (img )
30
+
31
+ def clear_metadata (self , image ):
32
+ if (
33
+ not hasattr (config , "clear_image_metadata" )
34
+ or not config .clear_image_metadata
35
+ ):
36
+ return image
37
+
38
+ if hasattr (image , "tag" ):
39
+ image .tag .clear ()
40
+
41
+ if hasattr (image , "tag_v2" ):
42
+ image .tag_v2 .clear ()
43
+
44
+ return image
Original file line number Diff line number Diff line change @@ -297,6 +297,14 @@ def import_modules():
297
297
default = "remotecv.metrics.logger_metrics" ,
298
298
help = "Metrics client, should be the full name of a python module" ,
299
299
)
300
+ @optgroup .option (
301
+ "--clear-image-metadata" ,
302
+ envvar = "CLEAR_IMAGE_METADATA" ,
303
+ show_envvar = True ,
304
+ is_flag = True ,
305
+ default = False ,
306
+ help = "Clears metadata when loading image" ,
307
+ )
300
308
@optgroup .group ("Memcached store arguments" )
301
309
@optgroup .option (
302
310
"--memcached-hosts" ,
@@ -335,6 +343,7 @@ def main(**params):
335
343
config .timeout = params ["timeout" ]
336
344
config .worker_ttl = params ["worker_ttl" ]
337
345
config .prune_dead_members = params ["prune_dead_members" ]
346
+ config .clear_image_metadata = params ["clear_image_metadata" ]
338
347
config .server_port = params ["server_port" ]
339
348
config .log_level = params ["level" ].upper ()
340
349
config .loader = import_module (params ["loader" ])
Original file line number Diff line number Diff line change 2
2
3
3
from preggy import expect
4
4
5
+ from remotecv .utils import config
5
6
from tests import create_image
6
7
7
8
@@ -20,3 +21,19 @@ def test_when_image_is_pallete(self):
20
21
image = create_image ("pallete.png" )
21
22
expect (image ).Not .to_be_null ()
22
23
expect (image .size ).to_equal ((3317 , 2083 ))
24
+
25
+ def test_should_clear_image_metadata (self ):
26
+ config .clear_image_metadata = True
27
+ image = create_image ("with_metadata.tiff" )
28
+ expect (image ).Not .to_be_null ()
29
+ expect (image .tag ).to_equal ({})
30
+ expect (image .tag_v2 ).to_equal ({})
31
+ expect (image .size ).to_equal ((41 , 48 ))
32
+
33
+ def test_should_not_clear_image_metadata (self ):
34
+ config .clear_image_metadata = False
35
+ image = create_image ("with_metadata.tiff" )
36
+ expect (image ).Not .to_be_null ()
37
+ expect (image .tag ).Not .to_equal ({})
38
+ expect (image .tag_v2 ).Not .to_equal ({})
39
+ expect (image .size ).to_equal ((41 , 48 ))
You can’t perform that action at this time.
0 commit comments