Skip to content

Commit

Permalink
Merge pull request #25
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Jul 31, 2020
2 parents 330acce + 4954541 commit ba726f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ public function transverse(): self
return $this;
}

/**
* @see http://www.imagemagick.org/script/command-line-options.php#threshold
*/
public function threshold(string $threshold): self
{
$this->command[] = '-threshold';
$this->command[] = $this->ref->threshold($threshold);

return $this;
}

/**
* /!\ Append a raw command to ImageMagick.
* Not safe! Use at your own risks!
Expand Down
28 changes: 28 additions & 0 deletions References.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,32 @@ public function interlace(string $interlaceType): string
'http://www.imagemagick.org/script/command-line-options.php#interlace'
));
}

/**
* Checks that threshold value is valid according to ImageMagick command line reference.
*/
public function threshold(string $threshold): string
{
$threshold = \trim($threshold);

if (is_numeric($threshold)) {
return $threshold;
}

if (substr($threshold, -1) == '%') {
$percentNumber = substr($threshold, 0, -1);
if (is_numeric($percentNumber)) {
return $threshold;
}
}

throw new \InvalidArgumentException(\sprintf(
'The specified threshold parameter (%s) is invalid.'."\n".
'The value must be an integer or a percentage value'."\n".
'Please refer to ImageMagick command line documentation:'."\n%s",
$threshold,
'http://www.imagemagick.org/script/command-line-options.php#threshold'
));

}
}

0 comments on commit ba726f9

Please sign in to comment.