Skip to content

Commit

Permalink
Merge pull request #22 from LeonB/patch-1
Browse files Browse the repository at this point in the history
Add option for 'tolerance' parameter in trim
  • Loading branch information
harto committed Oct 5, 2015
2 parents ce16636 + 079fe2a commit 061211e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Thumbor/Url/CommandSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ class CommandSet
* Trim surrounding space from the thumbnail. The top-left corner of the
* image is assumed to contain the background colour. To specify otherwise,
* pass either 'top-left' or 'bottom-right' as the $colourSource argument.
* For tolerance the euclidian distance between the colors of the reference pixel
* and the surrounding pixels is used. If the distance is within the
* tolerance they'll get trimmed. For a RGB image the tolerance would
* be within the range 0-442
*/
public function trim($colourSource = null)
public function trim($colourSource = null, $tolerance = null)
{
$this->trim = 'trim' . ($colourSource ? ":$colourSource" : '');
$this->trim = 'trim';
$this->trim .= $colourSource ? ":$colourSource" : '';
$this->trim .= $tolerance ? ":$tolerance" : '';
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Thumbor/Url/CommandSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function testTrim()
array('trim:bottom-right'),
$commandSet->toArray()
);
$commandSet->trim('top-left', 50);
$this->assertEquals(
array('trim:top-left:50'),
$commandSet->toArray()
);
}

public function testCrop()
Expand Down

0 comments on commit 061211e

Please sign in to comment.