| 1: | <?php | 
| 2: |  | 
| 3: |  | 
| 4: |  | 
| 5: |  | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: |  | 
| 13: |  | 
| 14: |  | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: |  | 
| 20: |  | 
| 21: |  | 
| 22: |  | 
| 23: |  | 
| 24: | namespace WideImage\Operation; | 
| 25: |  | 
| 26: | use WideImage\Exception\GDFunctionResultException; | 
| 27: |  | 
| 28: |  | 
| 29: |  | 
| 30: |  | 
| 31: |  | 
| 32: |  | 
| 33: | class ApplyFilter | 
| 34: | { | 
| 35: |  | 
| 36: |  | 
| 37: |  | 
| 38: |  | 
| 39: |  | 
| 40: | protected static $one_arg_filters = array(IMG_FILTER_SMOOTH, IMG_FILTER_CONTRAST, IMG_FILTER_BRIGHTNESS); | 
| 41: |  | 
| 42: |  | 
| 43: |  | 
| 44: |  | 
| 45: |  | 
| 46: |  | 
| 47: |  | 
| 48: |  | 
| 49: |  | 
| 50: |  | 
| 51: |  | 
| 52: | public function execute($image, $filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null) | 
| 53: | { | 
| 54: | $new = $image->asTrueColor(); | 
| 55: |  | 
| 56: | if (in_array($filter, static::$one_arg_filters)) { | 
| 57: | $res = imagefilter($new->getHandle(), $filter, $arg1); | 
| 58: | } elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) { | 
| 59: | $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2); | 
| 60: | } elseif ($filter == IMG_FILTER_COLORIZE) { | 
| 61: | $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4); | 
| 62: | } else { | 
| 63: | $res = imagefilter($new->getHandle(), $filter); | 
| 64: | } | 
| 65: |  | 
| 66: | if (!$res) { | 
| 67: | throw new GDFunctionResultException("imagefilter() returned false"); | 
| 68: | } | 
| 69: |  | 
| 70: | return $new; | 
| 71: | } | 
| 72: | } | 
| 73: |  |