Skip to content

Commit

Permalink
add clear image metadata option
Browse files Browse the repository at this point in the history
  • Loading branch information
devppjr committed Nov 13, 2023
1 parent 6fc5d49 commit e960b21
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions remotecv/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from PIL import Image as PilImage

from remotecv.utils import config

PilImage.IGNORE_DECODING_ERRORS = True
PilImage.MAXBLOCK = 2**25

Expand All @@ -23,4 +25,17 @@ def parse_image(self, image_buffer):
img.load()
except IOError:
pass

if config.clear_image_metadata:
return self.clear_metadata(img)

return img

def clear_metadata(self, image):
if hasattr(image, "tag"):
image.tag.clear()

if hasattr(image, "tag_v2"):
image.tag_v2.clear()

return image
9 changes: 9 additions & 0 deletions remotecv/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"])
Expand Down
Binary file added tests/fixtures/with_metadata.tiff
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from preggy import expect

from remotecv.utils import config
from tests import create_image


Expand All @@ -20,3 +21,19 @@ def test_when_image_is_pallete(self):
image = create_image("pallete.png")
expect(image).Not.to_be_null()
expect(image.size).to_equal((3317, 2083))

def test_should_clear_image_metadata(self):
config.clear_image_metadata = True
image = create_image("with_metadata.tiff")
expect(image).Not.to_be_null()
expect(image.tag).to_equal({})
expect(image.tag_v2).to_equal({})
expect(image.size).to_equal((41, 48))

def test_should_not_clear_image_metadata(self):
config.clear_image_metadata = False
image = create_image("with_metadata.tiff")
expect(image).Not.to_be_null()
expect(image.tag).Not.to_equal({})
expect(image.tag_v2).Not.to_equal({})
expect(image.size).to_equal((41, 48))

0 comments on commit e960b21

Please sign in to comment.