@@ -41,13 +41,14 @@ |
||
41 | 41 | |
42 | 42 | $width = $image->getWidth(); |
43 | 43 | $height = $image->getHeight(); |
44 | - for ($y = 0; $y < $height; $y++) |
|
45 | - imagecopy( |
|
44 | + for ($y = 0; $y < $height; $y++) { |
|
45 | + imagecopy( |
|
46 | 46 | $new->getHandle(), |
47 | 47 | $image->getHandle(), |
48 | 48 | 0, $y, 0, $height - $y - 1, |
49 | 49 | $width, 1 |
50 | 50 | ); |
51 | + } |
|
51 | 52 | return $new; |
52 | 53 | } |
53 | 54 | } |
@@ -48,11 +48,12 @@ discard block |
||
48 | 48 | $result->alphaBlending(true); |
49 | 49 | $result->saveAlpha(true); |
50 | 50 | |
51 | - if ($pct == 0) |
|
52 | - return $result; |
|
51 | + if ($pct == 0) { |
|
52 | + return $result; |
|
53 | + } |
|
53 | 54 | |
54 | - if ($pct < 100) |
|
55 | - imagecopymerge( |
|
55 | + if ($pct < 100) { |
|
56 | + imagecopymerge( |
|
56 | 57 | $result->getHandle(), |
57 | 58 | $overlay->getHandle(), |
58 | 59 | $x, $y, 0, 0, |
@@ -60,14 +61,15 @@ discard block |
||
60 | 61 | $overlay->getHeight(), |
61 | 62 | $pct |
62 | 63 | ); |
63 | - else |
|
64 | - imagecopy( |
|
64 | + } else { |
|
65 | + imagecopy( |
|
65 | 66 | $result->getHandle(), |
66 | 67 | $overlay->getHandle(), |
67 | 68 | $x, $y, 0, 0, |
68 | 69 | $overlay->getWidth(), |
69 | 70 | $overlay->getHeight() |
70 | 71 | ); |
72 | + } |
|
71 | 73 | |
72 | 74 | return $result; |
73 | 75 | } |
@@ -44,12 +44,14 @@ discard block |
||
44 | 44 | $top = WideImage_Coordinate::fix($image->getHeight(), $top); |
45 | 45 | |
46 | 46 | $width = $image->getWidth(); |
47 | - if ($width > $mask->getWidth()) |
|
48 | - $width = $mask->getWidth(); |
|
47 | + if ($width > $mask->getWidth()) { |
|
48 | + $width = $mask->getWidth(); |
|
49 | + } |
|
49 | 50 | |
50 | 51 | $height = $image->getHeight(); |
51 | - if ($height > $mask->getHeight()) |
|
52 | - $height = $mask->getHeight(); |
|
52 | + if ($height > $mask->getHeight()) { |
|
53 | + $height = $mask->getHeight(); |
|
54 | + } |
|
53 | 55 | |
54 | 56 | $result = $image->asTrueColor(); |
55 | 57 | $result->alphaBlending(false); |
@@ -62,34 +64,38 @@ discard block |
||
62 | 64 | $trgb['alpha'] = 127; |
63 | 65 | $destTransparentColor = $result->allocateColorAlpha($trgb); |
64 | 66 | $result->setTransparentColor($destTransparentColor); |
67 | + } else { |
|
68 | + $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127); |
|
65 | 69 | } |
66 | - else |
|
67 | - $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127); |
|
68 | 70 | |
69 | - for ($x = 0; $x < $width; $x++) |
|
70 | - for ($y = 0; $y < $height; $y++) |
|
71 | - if ($left + $x < $image->getWidth() && $top + $y < $image->getHeight()) |
|
71 | + for ($x = 0; $x < $width; $x++) { |
|
72 | + for ($y = 0; |
|
73 | + } |
|
74 | + $y < $height; $y++) { |
|
75 | + if ($left + $x < $image->getWidth() && $top + $y < $image->getHeight()) |
|
72 | 76 | { |
73 | 77 | $srcColor = $image->getColorAt($left + $x, $top + $y); |
74 | - if ($srcColor == $srcTransparentColor) |
|
75 | - $destColor = $destTransparentColor; |
|
76 | - else |
|
78 | + } |
|
79 | + if ($srcColor == $srcTransparentColor) { |
|
80 | + $destColor = $destTransparentColor; |
|
81 | + } else |
|
77 | 82 | { |
78 | 83 | $maskRGB = $mask->getRGBAt($x, $y); |
79 | - if ($maskRGB['red'] == 0) |
|
80 | - $destColor = $destTransparentColor; |
|
81 | - elseif ($srcColor >= 0) |
|
84 | + if ($maskRGB['red'] == 0) { |
|
85 | + $destColor = $destTransparentColor; |
|
86 | + } elseif ($srcColor >= 0) |
|
82 | 87 | { |
83 | 88 | $imageRGB = $image->getRGBAt($left + $x, $top + $y); |
84 | 89 | $level = ($maskRGB['red'] / 255) * (1 - $imageRGB['alpha'] / 127); |
85 | 90 | $imageRGB['alpha'] = 127 - round($level * 127); |
86 | - if ($imageRGB['alpha'] == 127) |
|
87 | - $destColor = $destTransparentColor; |
|
88 | - else |
|
89 | - $destColor = $result->allocateColorAlpha($imageRGB); |
|
91 | + if ($imageRGB['alpha'] == 127) { |
|
92 | + $destColor = $destTransparentColor; |
|
93 | + } else { |
|
94 | + $destColor = $result->allocateColorAlpha($imageRGB); |
|
95 | + } |
|
96 | + } else { |
|
97 | + $destColor = $destTransparentColor; |
|
90 | 98 | } |
91 | - else |
|
92 | - $destColor = $destTransparentColor; |
|
93 | 99 | } |
94 | 100 | $result->setColorAt($left + $x, $top + $y, $destColor); |
95 | 101 | } |
@@ -50,14 +50,15 @@ |
||
50 | 50 | { |
51 | 51 | $new = $image->asTrueColor(); |
52 | 52 | |
53 | - if (in_array($filter, self::$one_arg_filters)) |
|
54 | - imagefilter($new->getHandle(), $filter, $arg1); |
|
55 | - elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) |
|
56 | - imagefilter($new->getHandle(), $filter, $arg1, $arg2); |
|
57 | - elseif ($filter == IMG_FILTER_COLORIZE) |
|
58 | - imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4); |
|
59 | - else |
|
60 | - imagefilter($new->getHandle(), $filter); |
|
53 | + if (in_array($filter, self::$one_arg_filters)) { |
|
54 | + imagefilter($new->getHandle(), $filter, $arg1); |
|
55 | + } elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) { |
|
56 | + imagefilter($new->getHandle(), $filter, $arg1, $arg2); |
|
57 | + } elseif ($filter == IMG_FILTER_COLORIZE) { |
|
58 | + imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4); |
|
59 | + } else { |
|
60 | + imagefilter($new->getHandle(), $filter); |
|
61 | + } |
|
61 | 62 | |
62 | 63 | return $new; |
63 | 64 | } |
@@ -51,8 +51,9 @@ discard block |
||
51 | 51 | $left = 0; |
52 | 52 | } |
53 | 53 | |
54 | - if ($width > $img->getWidth() - $left) |
|
55 | - $width = $img->getWidth() - $left; |
|
54 | + if ($width > $img->getWidth() - $left) { |
|
55 | + $width = $img->getWidth() - $left; |
|
56 | + } |
|
56 | 57 | |
57 | 58 | if ($top < 0) |
58 | 59 | { |
@@ -60,8 +61,9 @@ discard block |
||
60 | 61 | $top = 0; |
61 | 62 | } |
62 | 63 | |
63 | - if ($height > $img->getHeight() - $top) |
|
64 | - $height = $img->getHeight() - $top; |
|
64 | + if ($height > $img->getHeight() - $top) { |
|
65 | + $height = $img->getHeight() - $top; |
|
66 | + } |
|
65 | 67 | |
66 | 68 | $new = $img->doCreate($width, $height); |
67 | 69 | |
@@ -71,8 +73,7 @@ discard block |
||
71 | 73 | imagecopyresized( |
72 | 74 | $new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height |
73 | 75 | ); |
74 | - } |
|
75 | - else |
|
76 | + } else |
|
76 | 77 | { |
77 | 78 | $new->alphaBlending(false); |
78 | 79 | $new->saveAlpha(true); |
@@ -41,32 +41,35 @@ |
||
41 | 41 | function execute($image, $angle, $bgColor, $ignoreTransparent) |
42 | 42 | { |
43 | 43 | $angle = -floatval($angle); |
44 | - if ($angle < 0) |
|
45 | - $angle = 360 + $angle; |
|
44 | + if ($angle < 0) { |
|
45 | + $angle = 360 + $angle; |
|
46 | + } |
|
46 | 47 | $angle = $angle % 360; |
47 | 48 | |
48 | - if ($angle == 0) |
|
49 | - return $image->copy(); |
|
49 | + if ($angle == 0) { |
|
50 | + return $image->copy(); |
|
51 | + } |
|
50 | 52 | |
51 | 53 | if ($bgColor === null) |
52 | 54 | { |
53 | - if ($image->isTransparent()) |
|
54 | - $bgColor = $image->getTransparentColor(); |
|
55 | - else |
|
55 | + if ($image->isTransparent()) { |
|
56 | + $bgColor = $image->getTransparentColor(); |
|
57 | + } else |
|
56 | 58 | { |
57 | 59 | $tc = array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127); |
58 | 60 | |
59 | 61 | if ($image->isTrueColor()) |
60 | 62 | { |
61 | 63 | $bgColor = $image->getExactColorAlpha($tc); |
62 | - if ($bgColor == -1) |
|
63 | - $bgColor = $image->allocateColorAlpha($tc); |
|
64 | - } |
|
65 | - else |
|
64 | + if ($bgColor == -1) { |
|
65 | + $bgColor = $image->allocateColorAlpha($tc); |
|
66 | + } |
|
67 | + } else |
|
66 | 68 | { |
67 | 69 | $bgColor = $image->getExactColor($tc); |
68 | - if ($bgColor == -1) |
|
69 | - $bgColor = $image->allocateColor($tc); |
|
70 | + if ($bgColor == -1) { |
|
71 | + $bgColor = $image->allocateColor($tc); |
|
72 | + } |
|
70 | 73 | } |
71 | 74 | } |
72 | 75 | } |
@@ -54,33 +54,35 @@ discard block |
||
54 | 54 | protected function prepareDimensions($img, $width, $height, $fit) |
55 | 55 | { |
56 | 56 | list($width, $height) = WideImage_Coordinate::fixForResize($img, $width, $height); |
57 | - if ($width === 0 || $height === 0) |
|
58 | - return array('width' => 0, 'height' => 0); |
|
57 | + if ($width === 0 || $height === 0) { |
|
58 | + return array('width' => 0, 'height' => 0); |
|
59 | + } |
|
59 | 60 | |
60 | - if ($fit == null) |
|
61 | - $fit = 'inside'; |
|
61 | + if ($fit == null) { |
|
62 | + $fit = 'inside'; |
|
63 | + } |
|
62 | 64 | |
63 | 65 | $dim = array(); |
64 | 66 | if ($fit == 'fill') |
65 | 67 | { |
66 | 68 | $dim['width'] = $width; |
67 | 69 | $dim['height'] = $height; |
68 | - } |
|
69 | - elseif ($fit == 'inside' || $fit == 'outside') |
|
70 | + } elseif ($fit == 'inside' || $fit == 'outside') |
|
70 | 71 | { |
71 | 72 | $rx = $img->getWidth() / $width; |
72 | 73 | $ry = $img->getHeight() / $height; |
73 | 74 | |
74 | - if ($fit == 'inside') |
|
75 | - $ratio = ($rx > $ry) ? $rx : $ry; |
|
76 | - else |
|
77 | - $ratio = ($rx < $ry) ? $rx : $ry; |
|
75 | + if ($fit == 'inside') { |
|
76 | + $ratio = ($rx > $ry) ? $rx : $ry; |
|
77 | + } else { |
|
78 | + $ratio = ($rx < $ry) ? $rx : $ry; |
|
79 | + } |
|
78 | 80 | |
79 | 81 | $dim['width'] = round($img->getWidth() / $ratio); |
80 | 82 | $dim['height'] = round($img->getHeight() / $ratio); |
83 | + } else { |
|
84 | + throw new WideImage_Operation_InvalidFitMethodException("{$fit} is not a valid resize-fit method."); |
|
81 | 85 | } |
82 | - else |
|
83 | - throw new WideImage_Operation_InvalidFitMethodException("{$fit} is not a valid resize-fit method."); |
|
84 | 86 | |
85 | 87 | return $dim; |
86 | 88 | } |
@@ -99,11 +101,13 @@ discard block |
||
99 | 101 | { |
100 | 102 | $dim = $this->prepareDimensions($img, $width, $height, $fit); |
101 | 103 | if (($scale === 'down' && ($dim['width'] >= $img->getWidth() && $dim['height'] >= $img->getHeight())) || |
102 | - ($scale === 'up' && ($dim['width'] <= $img->getWidth() && $dim['height'] <= $img->getHeight()))) |
|
103 | - $dim = array('width' => $img->getWidth(), 'height' => $img->getHeight()); |
|
104 | + ($scale === 'up' && ($dim['width'] <= $img->getWidth() && $dim['height'] <= $img->getHeight()))) { |
|
105 | + $dim = array('width' => $img->getWidth(), 'height' => $img->getHeight()); |
|
106 | + } |
|
104 | 107 | |
105 | - if ($dim['width'] <= 0 || $dim['height'] <= 0) |
|
106 | - throw new WideImage_Operation_InvalidResizeDimensionException("Both dimensions must be larger than 0."); |
|
108 | + if ($dim['width'] <= 0 || $dim['height'] <= 0) { |
|
109 | + throw new WideImage_Operation_InvalidResizeDimensionException("Both dimensions must be larger than 0."); |
|
110 | + } |
|
107 | 111 | |
108 | 112 | $new = WideImage_TrueColorImage::create($dim['width'], $dim['height']); |
109 | 113 | |
@@ -119,8 +123,7 @@ discard block |
||
119 | 123 | $img->getWidth(), |
120 | 124 | $img->getHeight() |
121 | 125 | ); |
122 | - } |
|
123 | - else |
|
126 | + } else |
|
124 | 127 | { |
125 | 128 | $new->alphaBlending(false); |
126 | 129 | $new->saveAlpha(true); |
@@ -58,15 +58,17 @@ discard block |
||
58 | 58 | { |
59 | 59 | $format = self::determineFormat($uri, $format); |
60 | 60 | |
61 | - if (array_key_exists($format, self::$mappers)) |
|
62 | - return self::$mappers[$format]; |
|
61 | + if (array_key_exists($format, self::$mappers)) { |
|
62 | + return self::$mappers[$format]; |
|
63 | + } |
|
63 | 64 | |
64 | 65 | $mapperClassName = 'WideImage_Mapper_' . $format; |
65 | 66 | if (!class_exists($mapperClassName, false)) |
66 | 67 | { |
67 | 68 | $mapperFileName = WideImage::path() . 'Mapper/' . $format . '.php'; |
68 | - if (file_exists($mapperFileName)) |
|
69 | - require_once($mapperFileName); |
|
69 | + if (file_exists($mapperFileName)) { |
|
70 | + require_once($mapperFileName); |
|
71 | + } |
|
70 | 72 | } |
71 | 73 | |
72 | 74 | if (class_exists($mapperClassName, false)) |
@@ -80,20 +82,23 @@ discard block |
||
80 | 82 | |
81 | 83 | static function determineFormat($uri, $format = null) |
82 | 84 | { |
83 | - if ($format == null) |
|
84 | - $format = self::extractExtension($uri); |
|
85 | + if ($format == null) { |
|
86 | + $format = self::extractExtension($uri); |
|
87 | + } |
|
85 | 88 | |
86 | 89 | // mime-type match |
87 | - if (preg_match('~[a-z]*/[a-z-]*~i', $format)) |
|
88 | - if (isset(self::$mimeTable[strtolower($format)])) |
|
90 | + if (preg_match('~[a-z]*/[a-z-]*~i', $format)) { |
|
91 | + if (isset(self::$mimeTable[strtolower($format)])) |
|
89 | 92 | { |
90 | 93 | return self::$mimeTable[strtolower($format)]; |
94 | + } |
|
91 | 95 | } |
92 | 96 | |
93 | 97 | // clean the string |
94 | 98 | $format = strtoupper(preg_replace('/[^a-z0-9_-]/i', '', $format)); |
95 | - if ($format == 'JPG') |
|
96 | - $format = 'JPEG'; |
|
99 | + if ($format == 'JPG') { |
|
100 | + $format = 'JPEG'; |
|
101 | + } |
|
97 | 102 | |
98 | 103 | return $format; |
99 | 104 | } |
@@ -106,10 +111,11 @@ discard block |
||
106 | 111 | static function extractExtension($uri) |
107 | 112 | { |
108 | 113 | $p = strrpos($uri, '.'); |
109 | - if ($p === false) |
|
110 | - return ''; |
|
111 | - else |
|
112 | - return substr($uri, $p + 1); |
|
114 | + if ($p === false) { |
|
115 | + return ''; |
|
116 | + } else { |
|
117 | + return substr($uri, $p + 1); |
|
118 | + } |
|
113 | 119 | } |
114 | 120 | } |
115 | 121 | ?> |
116 | 122 | \ No newline at end of file |
@@ -44,10 +44,11 @@ |
||
44 | 44 | if (!class_exists($opClassName, false)) |
45 | 45 | { |
46 | 46 | $fileName = WideImage::path() . 'Operation/' . $operationName . '.php'; |
47 | - if (file_exists($fileName)) |
|
48 | - require_once($fileName); |
|
49 | - else |
|
50 | - throw new WideImage_UnknownImageOperationException("Can't load '{$operationName}' operation."); |
|
47 | + if (file_exists($fileName)) { |
|
48 | + require_once($fileName); |
|
49 | + } else { |
|
50 | + throw new WideImage_UnknownImageOperationException("Can't load '{$operationName}' operation."); |
|
51 | + } |
|
51 | 52 | } |
52 | 53 | self::$cache[$operationName] = new $opClassName(); |
53 | 54 | } |