Skip to content
Browse files

Support trim options.

  • Loading branch information...
1 parent 48577f5 commit dc7b110643994aefd65b902fa67844c82145bb9c @wichert wichert committed
Showing with 34 additions and 0 deletions.
  1. +9 −0 libthumbor/url.py
  2. +25 −0 tests/test_url_composer.py
View
9 libthumbor/url.py
@@ -71,6 +71,15 @@ def get_url_parts(**options):
if options.get('meta', False):
url_parts.append('meta')
+ trim = options.get('trim', None)
+ if trim:
+ bits = ['trim']
+ if not isinstance(trim, bool):
+ bits.append(trim[0] if trim[0] else '')
+ if trim[1]:
+ bits.append(str(trim[1]))
+ url_parts.append(':'.join(bits))
+
crop = options.get('crop', None)
if crop:
crop_left = crop[0][0]
View
25 tests/test_url_composer.py
@@ -423,6 +423,31 @@ def test_proper_meta():
assert url == 'meta/84996242f65a4d864aceb125e1c4c5ba', url
+
+def test_trim_standard():
+ url = url_for(trim=True,
+ image_url=IMAGE_URL)
+ assert url == 'trim/84996242f65a4d864aceb125e1c4c5ba', url
+
+
+def test_trim_pixel_and_tolerance():
+ url = url_for(trim=('bottom-right', 15),
+ image_url=IMAGE_URL)
+ assert url == 'trim:bottom-right:15/84996242f65a4d864aceb125e1c4c5ba', url
+
+
+def test_trim_pixel_only():
+ url = url_for(trim=('top-left', None),
+ image_url=IMAGE_URL)
+ assert url == 'trim:top-left/84996242f65a4d864aceb125e1c4c5ba', url
+
+
+def test_trim_tolerance_only():
+ url = url_for(trim=(None, 15),
+ image_url=IMAGE_URL)
+ assert url == 'trim::15/84996242f65a4d864aceb125e1c4c5ba', url
+
+
def test_manual_crop_1():
'''test_manual_crop_1
Given

0 comments on commit dc7b110

Please sign in to comment.
Something went wrong with that request. Please try again.