Skip to content

Commit

Permalink
Require an option to disable the watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jul 4, 2017
1 parent 624d429 commit 3480360
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions memegen/domain/image.py
Expand Up @@ -4,7 +4,6 @@

from PIL import Image as ImageFile, ImageFont, ImageDraw, ImageFilter

FINGERPRINT_WATERMARK = True

log = logging.getLogger(__name__)

Expand All @@ -31,9 +30,8 @@ def path(self):
return None

base = os.path.join(self.root, self.template.key, self.text.path)
custom = [self.style, self.font, self.width, self.height]
if FINGERPRINT_WATERMARK:
custom.append(self.watermark)
custom = [self.style, self.font, self.watermark,
self.width, self.height]

if any(custom):
slug = self.hash(custom)
Expand Down
12 changes: 7 additions & 5 deletions memegen/routes/image.py
Expand Up @@ -126,12 +126,14 @@ def get_encoded(code):


def _get_watermark(_request, watermark):
if watermark == 'none':
ref = _request.environ.get('HTTP_REFERER', "")
log.debug("HTTP_REFERER: %r", ref)
for option in current_app.config['WATERMARK_OPTIONS']:
if option in ref:
return None

if watermark:
return watermark

referer = _request.environ.get('HTTP_REFERER', "")
for option in current_app.config['WATERMARK_OPTIONS']:
if option in referer:
return None

return current_app.config['WATERMARK_OPTIONS'][0]
2 changes: 1 addition & 1 deletion memegen/settings.py
Expand Up @@ -50,7 +50,7 @@ class TestConfig(Config):
DEBUG = True
TESTING = True

WATERMARK_OPTIONS = ['test']
WATERMARK_OPTIONS = ['test', '']


class DevConfig(Config):
Expand Down
4 changes: 1 addition & 3 deletions tests/test_images.py
@@ -1,7 +1,6 @@
# pylint: disable=unused-variable,unused-argument,misplaced-comparison-constant,expression-not-assigned

import os
from unittest.mock import patch

import pytest
from expecter import expect
Expand All @@ -19,13 +18,12 @@ def describe_get():

def describe_visible():

@patch('memegen.domain.image.FINGERPRINT_WATERMARK', False)
def with_nominal_text(client):
path = os.path.join(IMAGES, 'iw', 'hello', 'world' + '.img')
if os.path.exists(path):
os.remove(path)

response = client.get("/iw/hello/world.jpg")
response = client.get("/iw/hello/world.jpg?watermark=none")

assert 200 == response.status_code
assert 'image/jpeg' == response.mimetype
Expand Down

0 comments on commit 3480360

Please sign in to comment.