File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff 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!
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments