File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -222,4 +222,29 @@ 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 ): float
230+ {
231+ $ threshold = \trim ($ threshold );
232+
233+ if (substr ($ threshold , -1 ) == '% ' ) {
234+ $ percent_num = substr ($ threshold , 0 , -1 );
235+ if (is_numeric ($ percent_num ))
236+ return $ threshold ;
237+ } else {
238+ if (is_int (filter_var ($ threshold , FILTER_VALIDATE_INT )) && intval ($ threshold ) >= 0 )
239+ return $ threshold ;
240+ }
241+
242+ throw new \InvalidArgumentException (\sprintf (
243+ 'The specified threshold parameter (%s) is invalid. ' ."\n" .
244+ 'The value must be in percentage or an absolute integer ' ."\n" .
245+ 'Please refer to ImageMagick command line documentation: ' ."\n%s " ,
246+ $ threshold , 'http://www.imagemagick.org/script/command-line-options.php#threshold '
247+ ));
248+
249+ }
225250}
You can’t perform that action at this time.
0 commit comments