Skip to content

Commit 061211e

Browse files
committed
Merge pull request 99designs#22 from LeonB/patch-1
Add option for 'tolerance' parameter in trim
2 parents ce16636 + 079fe2a commit 061211e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/Thumbor/Url/CommandSet.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ class CommandSet
2121
* Trim surrounding space from the thumbnail. The top-left corner of the
2222
* image is assumed to contain the background colour. To specify otherwise,
2323
* pass either 'top-left' or 'bottom-right' as the $colourSource argument.
24+
* For tolerance the euclidian distance between the colors of the reference pixel
25+
* and the surrounding pixels is used. If the distance is within the
26+
* tolerance they'll get trimmed. For a RGB image the tolerance would
27+
* be within the range 0-442
2428
*/
25-
public function trim($colourSource = null)
29+
public function trim($colourSource = null, $tolerance = null)
2630
{
27-
$this->trim = 'trim' . ($colourSource ? ":$colourSource" : '');
31+
$this->trim = 'trim';
32+
$this->trim .= $colourSource ? ":$colourSource" : '';
33+
$this->trim .= $tolerance ? ":$tolerance" : '';
2834
}
2935

3036
/**

tests/Thumbor/Url/CommandSetTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function testTrim()
2828
array('trim:bottom-right'),
2929
$commandSet->toArray()
3030
);
31+
$commandSet->trim('top-left', 50);
32+
$this->assertEquals(
33+
array('trim:top-left:50'),
34+
$commandSet->toArray()
35+
);
3136
}
3237

3338
public function testCrop()

0 commit comments

Comments
 (0)