1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
<?php
namespace Scene7\Commands;
trait UnsharpMask
{
public function setUnsharpMask($amount, $radius = null, $threshold = null, $monochrome = null)
{
$amount = (float) $amount;
if ($amount < 0 || $amount > 5) {
throw new \InvalidArgumentException('Invalid amount');
}
if ($radius !== null) {
$radius = (float) $radius;
if ($radius < 0 || $radius > 250) {
throw new \InvalidArgumentException('Invalid radius');
}
}
if ($threshold !== null) {
$threshold = (float) $threshold;
if ($threshold < 0 || $threshold > 255) {
throw new \InvalidArgumentException('Invalid threshold');
}
}
$mask = $amount;
if ($radius !== null || $threshold !== null || $monochrome !== null) {
$mask .= ',' . $radius;
}
if ($threshold !== null || $monochrome != null) {
$mask .= ',' . $threshold;
}
if ($monochrome !== null) {
$mask .= ',' . (int) (bool) $monochrome;
}
$this->addCommand(['op_usm' => $mask]);
return $this;
}
}