Skip to content

Commit ba726f9

Browse files
committed
Merge pull request #25
2 parents 330acce + 4954541 commit ba726f9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Command.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,17 @@ public function transverse(): self
638638
return $this;
639639
}
640640

641+
/**
642+
* @see http://www.imagemagick.org/script/command-line-options.php#threshold
643+
*/
644+
public function threshold(string $threshold): self
645+
{
646+
$this->command[] = '-threshold';
647+
$this->command[] = $this->ref->threshold($threshold);
648+
649+
return $this;
650+
}
651+
641652
/**
642653
* /!\ Append a raw command to ImageMagick.
643654
* Not safe! Use at your own risks!

References.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,32 @@ public function interlace(string $interlaceType): string
222222
'http://www.imagemagick.org/script/command-line-options.php#interlace'
223223
));
224224
}
225+
226+
/**
227+
* Checks that threshold value is valid according to ImageMagick command line reference.
228+
*/
229+
public function threshold(string $threshold): string
230+
{
231+
$threshold = \trim($threshold);
232+
233+
if (is_numeric($threshold)) {
234+
return $threshold;
235+
}
236+
237+
if (substr($threshold, -1) == '%') {
238+
$percentNumber = substr($threshold, 0, -1);
239+
if (is_numeric($percentNumber)) {
240+
return $threshold;
241+
}
242+
}
243+
244+
throw new \InvalidArgumentException(\sprintf(
245+
'The specified threshold parameter (%s) is invalid.'."\n".
246+
'The value must be an integer or a percentage value'."\n".
247+
'Please refer to ImageMagick command line documentation:'."\n%s",
248+
$threshold,
249+
'http://www.imagemagick.org/script/command-line-options.php#threshold'
250+
));
251+
252+
}
225253
}

0 commit comments

Comments
 (0)