@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $string = strip_tags($string); |
49 | 49 | $string = trim($string); |
50 | 50 | $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters |
51 | - $string = str_replace(array('+', '=', '!', ',', '.',';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
51 | + $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
52 | 52 | $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. |
53 | 53 | $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. |
54 | 54 | $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | { |
67 | 67 | $encoding = mb_detect_encoding($string, mb_detect_order(), false); |
68 | 68 | |
69 | - if($encoding == "UTF-8") { |
|
69 | + if ($encoding == "UTF-8") { |
|
70 | 70 | $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); |
71 | 71 | } |
72 | 72 |
@@ -9,76 +9,76 @@ |
||
9 | 9 | |
10 | 10 | class CharacterFilter |
11 | 11 | { |
12 | - protected $originalString; |
|
13 | - protected $filteredString = ''; |
|
12 | + protected $originalString; |
|
13 | + protected $filteredString = ''; |
|
14 | 14 | |
15 | - /** |
|
16 | - * CharacterFilter constructor. |
|
17 | - * |
|
18 | - * @param $string |
|
19 | - */ |
|
20 | - public function __construct($string) |
|
21 | - { |
|
22 | - $this->originalString = $string; |
|
23 | - $string = $this->convertToUTF8($string); |
|
24 | - $string = mb_strtolower($string); |
|
25 | - $string = $this->filterSpecialCharacters($string); |
|
26 | - $this->filteredString = $string; |
|
27 | - } |
|
15 | + /** |
|
16 | + * CharacterFilter constructor. |
|
17 | + * |
|
18 | + * @param $string |
|
19 | + */ |
|
20 | + public function __construct($string) |
|
21 | + { |
|
22 | + $this->originalString = $string; |
|
23 | + $string = $this->convertToUTF8($string); |
|
24 | + $string = mb_strtolower($string); |
|
25 | + $string = $this->filterSpecialCharacters($string); |
|
26 | + $this->filteredString = $string; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Returns the filtered string |
|
31 | - * @return string|void |
|
32 | - */ |
|
33 | - public function __toString() |
|
34 | - { |
|
35 | - return $this->filteredString; |
|
36 | - } |
|
29 | + /** |
|
30 | + * Returns the filtered string |
|
31 | + * @return string|void |
|
32 | + */ |
|
33 | + public function __toString() |
|
34 | + { |
|
35 | + return $this->filteredString; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Filter out all special characters, like punctuation and characters with accents |
|
40 | - * |
|
41 | - * @param $string |
|
42 | - * |
|
43 | - * @return mixed|string |
|
44 | - */ |
|
45 | - private function filterSpecialCharacters($string) |
|
46 | - { |
|
47 | - $string = str_replace('<', ' <', $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething |
|
48 | - $string = strip_tags($string); |
|
49 | - $string = trim($string); |
|
50 | - $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters |
|
51 | - $string = str_replace(array('+', '=', '!', ',', '.',';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
52 | - $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. |
|
53 | - $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. |
|
54 | - $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space |
|
55 | - $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space |
|
56 | - return $string; |
|
57 | - } |
|
38 | + /** |
|
39 | + * Filter out all special characters, like punctuation and characters with accents |
|
40 | + * |
|
41 | + * @param $string |
|
42 | + * |
|
43 | + * @return mixed|string |
|
44 | + */ |
|
45 | + private function filterSpecialCharacters($string) |
|
46 | + { |
|
47 | + $string = str_replace('<', ' <', $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething |
|
48 | + $string = strip_tags($string); |
|
49 | + $string = trim($string); |
|
50 | + $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters |
|
51 | + $string = str_replace(array('+', '=', '!', ',', '.',';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
52 | + $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. |
|
53 | + $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. |
|
54 | + $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space |
|
55 | + $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space |
|
56 | + return $string; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Convert the string to UTF-8 encoding |
|
61 | - * @param $string |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - private function convertToUTF8($string) |
|
66 | - { |
|
67 | - $encoding = mb_detect_encoding($string, mb_detect_order(), false); |
|
59 | + /** |
|
60 | + * Convert the string to UTF-8 encoding |
|
61 | + * @param $string |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + private function convertToUTF8($string) |
|
66 | + { |
|
67 | + $encoding = mb_detect_encoding($string, mb_detect_order(), false); |
|
68 | 68 | |
69 | - if($encoding == "UTF-8") { |
|
70 | - $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); |
|
71 | - } |
|
69 | + if($encoding == "UTF-8") { |
|
70 | + $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); |
|
71 | + } |
|
72 | 72 | |
73 | - $out = iconv(mb_detect_encoding($string, mb_detect_order(), false), "UTF-8//IGNORE", $string); |
|
74 | - return $out; |
|
75 | - } |
|
73 | + $out = iconv(mb_detect_encoding($string, mb_detect_order(), false), "UTF-8//IGNORE", $string); |
|
74 | + return $out; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return mixed|string |
|
79 | - */ |
|
80 | - public function getFilteredString() |
|
81 | - { |
|
82 | - return $this->filteredString; |
|
83 | - } |
|
77 | + /** |
|
78 | + * @return mixed|string |
|
79 | + */ |
|
80 | + public function getFilteredString() |
|
81 | + { |
|
82 | + return $this->filteredString; |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | \ No newline at end of file |
@@ -10,14 +10,14 @@ |
||
10 | 10 | |
11 | 11 | namespace CloudControl\Cms\images |
12 | 12 | { |
13 | - abstract class IMethod |
|
14 | - { |
|
15 | - /** |
|
16 | - * Method stub, use for executing the manipulation |
|
17 | - * |
|
18 | - * @param resource $imageResource |
|
19 | - * @return resource |
|
20 | - */ |
|
21 | - abstract public function Execute($imageResource); |
|
22 | - } |
|
13 | + abstract class IMethod |
|
14 | + { |
|
15 | + /** |
|
16 | + * Method stub, use for executing the manipulation |
|
17 | + * |
|
18 | + * @param resource $imageResource |
|
19 | + * @return resource |
|
20 | + */ |
|
21 | + abstract public function Execute($imageResource); |
|
22 | + } |
|
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -5,144 +5,144 @@ |
||
5 | 5 | use CloudControl\Cms\cc\StringUtil; |
6 | 6 | |
7 | 7 | /** |
8 | - * Class ImageResizer |
|
9 | - * @package CloudControl\Cms\images |
|
10 | - */ |
|
11 | - class ImageResizer |
|
12 | - { |
|
13 | - protected $imageSet; |
|
8 | + * Class ImageResizer |
|
9 | + * @package CloudControl\Cms\images |
|
10 | + */ |
|
11 | + class ImageResizer |
|
12 | + { |
|
13 | + protected $imageSet; |
|
14 | 14 | |
15 | - /** |
|
16 | - * ImageResizer constructor. |
|
17 | - * |
|
18 | - * @param $imageSet |
|
19 | - */ |
|
20 | - public function __construct($imageSet) |
|
21 | - { |
|
22 | - $this->imageSet = $imageSet; |
|
23 | - } |
|
15 | + /** |
|
16 | + * ImageResizer constructor. |
|
17 | + * |
|
18 | + * @param $imageSet |
|
19 | + */ |
|
20 | + public function __construct($imageSet) |
|
21 | + { |
|
22 | + $this->imageSet = $imageSet; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param $imagePath |
|
27 | - * |
|
28 | - * @return array |
|
29 | - * @throws \Exception |
|
30 | - */ |
|
31 | - public function applyImageSetToImage($imagePath) |
|
32 | - { |
|
33 | - $returnFileNames = array(); |
|
34 | - $filename = ''; |
|
35 | - if (file_exists($imagePath)) { |
|
36 | - foreach ($this->imageSet as $set) { |
|
37 | - if ($set->method == 'resize') { |
|
38 | - $filename = $this->resize($imagePath, $set->width, $set->height); |
|
39 | - } elseif ($set->method == 'smartcrop') { |
|
40 | - $filename = $this->smartcrop($imagePath, $set->width, $set->height); |
|
41 | - } elseif ($set->method == 'boxcrop') { |
|
42 | - $filename = $this->boxcrop($imagePath, $set->width, $set->height); |
|
43 | - } |
|
44 | - $returnFileNames[$set->slug] = $filename; |
|
45 | - } |
|
46 | - return $returnFileNames; |
|
47 | - } else { |
|
48 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
49 | - } |
|
50 | - } |
|
25 | + /** |
|
26 | + * @param $imagePath |
|
27 | + * |
|
28 | + * @return array |
|
29 | + * @throws \Exception |
|
30 | + */ |
|
31 | + public function applyImageSetToImage($imagePath) |
|
32 | + { |
|
33 | + $returnFileNames = array(); |
|
34 | + $filename = ''; |
|
35 | + if (file_exists($imagePath)) { |
|
36 | + foreach ($this->imageSet as $set) { |
|
37 | + if ($set->method == 'resize') { |
|
38 | + $filename = $this->resize($imagePath, $set->width, $set->height); |
|
39 | + } elseif ($set->method == 'smartcrop') { |
|
40 | + $filename = $this->smartcrop($imagePath, $set->width, $set->height); |
|
41 | + } elseif ($set->method == 'boxcrop') { |
|
42 | + $filename = $this->boxcrop($imagePath, $set->width, $set->height); |
|
43 | + } |
|
44 | + $returnFileNames[$set->slug] = $filename; |
|
45 | + } |
|
46 | + return $returnFileNames; |
|
47 | + } else { |
|
48 | + throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $imagePath |
|
54 | - * @param string $width |
|
55 | - * @param string $height |
|
56 | - * @return string |
|
57 | - * @throws \Exception |
|
58 | - */ |
|
59 | - public function resize($imagePath='', $width='',$height='') |
|
60 | - { |
|
61 | - $modifier = '-r' . $width . 'x' . $height; |
|
62 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
63 | - } |
|
52 | + /** |
|
53 | + * @param string $imagePath |
|
54 | + * @param string $width |
|
55 | + * @param string $height |
|
56 | + * @return string |
|
57 | + * @throws \Exception |
|
58 | + */ |
|
59 | + public function resize($imagePath='', $width='',$height='') |
|
60 | + { |
|
61 | + $modifier = '-r' . $width . 'x' . $height; |
|
62 | + return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param string $imagePath |
|
67 | - * @param string $width |
|
68 | - * @param string $height |
|
69 | - * @return string |
|
70 | - * @throws \Exception |
|
71 | - */ |
|
72 | - public function smartcrop($imagePath='', $width='',$height='') |
|
73 | - { |
|
74 | - $modifier = '-s' . $width . 'x' . $height; |
|
75 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
76 | - } |
|
65 | + /** |
|
66 | + * @param string $imagePath |
|
67 | + * @param string $width |
|
68 | + * @param string $height |
|
69 | + * @return string |
|
70 | + * @throws \Exception |
|
71 | + */ |
|
72 | + public function smartcrop($imagePath='', $width='',$height='') |
|
73 | + { |
|
74 | + $modifier = '-s' . $width . 'x' . $height; |
|
75 | + return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $imagePath |
|
80 | - * @param string $width |
|
81 | - * @param string $height |
|
82 | - * @return string |
|
83 | - * @throws \Exception |
|
84 | - */ |
|
85 | - public function boxcrop($imagePath='', $width='',$height='') |
|
86 | - { |
|
87 | - $modifier = '-b' . $width . 'x' . $height; |
|
88 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
89 | - } |
|
78 | + /** |
|
79 | + * @param string $imagePath |
|
80 | + * @param string $width |
|
81 | + * @param string $height |
|
82 | + * @return string |
|
83 | + * @throws \Exception |
|
84 | + */ |
|
85 | + public function boxcrop($imagePath='', $width='',$height='') |
|
86 | + { |
|
87 | + $modifier = '-b' . $width . 'x' . $height; |
|
88 | + return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param $imagePath |
|
93 | - * @param string $modifier |
|
94 | - * |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - private function modifyName($imagePath, $modifier='') |
|
98 | - { |
|
99 | - $filename = basename($imagePath); |
|
100 | - $path = dirname($imagePath); |
|
101 | - $fileParts = explode('.', $filename); |
|
102 | - if (count($fileParts) > 1) { |
|
103 | - $extension = end($fileParts); |
|
104 | - array_pop($fileParts); |
|
105 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
106 | - $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
107 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
108 | - } else { |
|
109 | - $filename = StringUtil::slugify($filename); |
|
110 | - } |
|
91 | + /** |
|
92 | + * @param $imagePath |
|
93 | + * @param string $modifier |
|
94 | + * |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + private function modifyName($imagePath, $modifier='') |
|
98 | + { |
|
99 | + $filename = basename($imagePath); |
|
100 | + $path = dirname($imagePath); |
|
101 | + $fileParts = explode('.', $filename); |
|
102 | + if (count($fileParts) > 1) { |
|
103 | + $extension = end($fileParts); |
|
104 | + array_pop($fileParts); |
|
105 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
106 | + $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
107 | + $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
108 | + } else { |
|
109 | + $filename = StringUtil::slugify($filename); |
|
110 | + } |
|
111 | 111 | |
112 | - if (file_exists($path . '/' . $filename)) { |
|
113 | - $fileParts = explode('.', $filename); |
|
114 | - if (count($fileParts) > 1) { |
|
115 | - $extension = end($fileParts); |
|
116 | - array_pop($fileParts); |
|
117 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
118 | - $fileNameWithoutExtension .= '-copy'; |
|
119 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
120 | - } else { |
|
121 | - $filename .= '-copy'; |
|
122 | - } |
|
123 | - return $this->modifyName($path . '/' . $filename); |
|
124 | - } |
|
125 | - return $path . '/' . $filename; |
|
126 | - } |
|
112 | + if (file_exists($path . '/' . $filename)) { |
|
113 | + $fileParts = explode('.', $filename); |
|
114 | + if (count($fileParts) > 1) { |
|
115 | + $extension = end($fileParts); |
|
116 | + array_pop($fileParts); |
|
117 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
118 | + $fileNameWithoutExtension .= '-copy'; |
|
119 | + $filename = $fileNameWithoutExtension . '.' . $extension; |
|
120 | + } else { |
|
121 | + $filename .= '-copy'; |
|
122 | + } |
|
123 | + return $this->modifyName($path . '/' . $filename); |
|
124 | + } |
|
125 | + return $path . '/' . $filename; |
|
126 | + } |
|
127 | 127 | |
128 | - private function applyMethod($method, $imagePath, $width, $height, $modifier) |
|
129 | - { |
|
130 | - $method = 'CloudControl\Cms\\images\\methods\\' . $method; |
|
131 | - $destination = $this->modifyName($imagePath, $modifier); |
|
132 | - if (file_exists($imagePath)) { |
|
133 | - $image = new Image(); |
|
134 | - $image->loadImage($imagePath); |
|
135 | - $resize = new $method(); |
|
136 | - $resize->SetWidth($width); |
|
137 | - $resize->SetHeight($height); |
|
138 | - $resizedImageResource = $resize->Execute($image->getImageResource()); |
|
139 | - $resizedImage = new Image(); |
|
140 | - $resizedImage->loadImage($resizedImageResource); |
|
141 | - $resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80); |
|
142 | - return basename($destination); |
|
143 | - } else { |
|
144 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
128 | + private function applyMethod($method, $imagePath, $width, $height, $modifier) |
|
129 | + { |
|
130 | + $method = 'CloudControl\Cms\\images\\methods\\' . $method; |
|
131 | + $destination = $this->modifyName($imagePath, $modifier); |
|
132 | + if (file_exists($imagePath)) { |
|
133 | + $image = new Image(); |
|
134 | + $image->loadImage($imagePath); |
|
135 | + $resize = new $method(); |
|
136 | + $resize->SetWidth($width); |
|
137 | + $resize->SetHeight($height); |
|
138 | + $resizedImageResource = $resize->Execute($image->getImageResource()); |
|
139 | + $resizedImage = new Image(); |
|
140 | + $resizedImage->loadImage($resizedImageResource); |
|
141 | + $resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80); |
|
142 | + return basename($destination); |
|
143 | + } else { |
|
144 | + throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | \ No newline at end of file |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | * @throws \Exception |
58 | 58 | */ |
59 | - public function resize($imagePath='', $width='',$height='') |
|
59 | + public function resize($imagePath = '', $width = '', $height = '') |
|
60 | 60 | { |
61 | 61 | $modifier = '-r' . $width . 'x' . $height; |
62 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
62 | + return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | * @return string |
70 | 70 | * @throws \Exception |
71 | 71 | */ |
72 | - public function smartcrop($imagePath='', $width='',$height='') |
|
72 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
73 | 73 | { |
74 | 74 | $modifier = '-s' . $width . 'x' . $height; |
75 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
75 | + return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @return string |
83 | 83 | * @throws \Exception |
84 | 84 | */ |
85 | - public function boxcrop($imagePath='', $width='',$height='') |
|
85 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
86 | 86 | { |
87 | 87 | $modifier = '-b' . $width . 'x' . $height; |
88 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
88 | + return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return string |
96 | 96 | */ |
97 | - private function modifyName($imagePath, $modifier='') |
|
97 | + private function modifyName($imagePath, $modifier = '') |
|
98 | 98 | { |
99 | 99 | $filename = basename($imagePath); |
100 | 100 | $path = dirname($imagePath); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | array_pop($fileParts); |
105 | 105 | $fileNameWithoutExtension = implode('-', $fileParts); |
106 | 106 | $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
107 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
107 | + $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
108 | 108 | } else { |
109 | 109 | $filename = StringUtil::slugify($filename); |
110 | 110 | } |
@@ -16,174 +16,174 @@ |
||
16 | 16 | use CloudControl\Cms\images\IMethod; |
17 | 17 | |
18 | 18 | class Watermark extends IMethod |
19 | - { |
|
20 | - protected $_x = 0; |
|
21 | - protected $_y = 0; |
|
22 | - protected $_transparency = 100; |
|
19 | + { |
|
20 | + protected $_x = 0; |
|
21 | + protected $_y = 0; |
|
22 | + protected $_transparency = 100; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var Image |
|
26 | - */ |
|
27 | - protected $_watermark; |
|
24 | + /** |
|
25 | + * @var Image |
|
26 | + */ |
|
27 | + protected $_watermark; |
|
28 | 28 | |
29 | - protected function init() |
|
30 | - {} |
|
29 | + protected function init() |
|
30 | + {} |
|
31 | 31 | |
32 | - /** |
|
33 | - * Sets transparency for watermark |
|
34 | - * |
|
35 | - * @param int $transparency |
|
36 | - * @return self |
|
37 | - */ |
|
38 | - public function SetTransparency($transparency) |
|
39 | - { |
|
40 | - $this->_transparency = intval($transparency); |
|
41 | - return $this; |
|
42 | - } |
|
32 | + /** |
|
33 | + * Sets transparency for watermark |
|
34 | + * |
|
35 | + * @param int $transparency |
|
36 | + * @return self |
|
37 | + */ |
|
38 | + public function SetTransparency($transparency) |
|
39 | + { |
|
40 | + $this->_transparency = intval($transparency); |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Use build-in logic to position the watermark |
|
46 | - * |
|
47 | - * @param string $x |
|
48 | - * @param string $y |
|
49 | - * @return self |
|
50 | - */ |
|
51 | - public function SetPosition($x, $y) |
|
52 | - { |
|
53 | - $this->SetX($x); |
|
54 | - $this->SetY($y); |
|
55 | - return $this; |
|
56 | - } |
|
44 | + /** |
|
45 | + * Use build-in logic to position the watermark |
|
46 | + * |
|
47 | + * @param string $x |
|
48 | + * @param string $y |
|
49 | + * @return self |
|
50 | + */ |
|
51 | + public function SetPosition($x, $y) |
|
52 | + { |
|
53 | + $this->SetX($x); |
|
54 | + $this->SetY($y); |
|
55 | + return $this; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Use build-in logic to position the x of watermark |
|
60 | - * |
|
61 | - * @param resource $imageResource |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - protected function calculateX($imageResource) |
|
65 | - { |
|
66 | - if (intval($this->_x) === $this->_x) return $this->_x; |
|
58 | + /** |
|
59 | + * Use build-in logic to position the x of watermark |
|
60 | + * |
|
61 | + * @param resource $imageResource |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + protected function calculateX($imageResource) |
|
65 | + { |
|
66 | + if (intval($this->_x) === $this->_x) return $this->_x; |
|
67 | 67 | |
68 | - $x = strtolower($this->_x); |
|
68 | + $x = strtolower($this->_x); |
|
69 | 69 | |
70 | - $imageWidth = imagesx($imageResource); |
|
71 | - $watermarkWidth = imagesx($this->GetWatermark()->getImageResource()); |
|
70 | + $imageWidth = imagesx($imageResource); |
|
71 | + $watermarkWidth = imagesx($this->GetWatermark()->getImageResource()); |
|
72 | 72 | |
73 | - if ($x == 'left') { |
|
74 | - $x = 0; |
|
75 | - } elseif ($x == 'center') { |
|
76 | - $x = $imageWidth / 2 - ($watermarkWidth / 2); |
|
77 | - } elseif ($x == 'right') { |
|
78 | - $x = $imageWidth - $watermarkWidth; |
|
79 | - } |
|
80 | - return intval($x); |
|
81 | - } |
|
73 | + if ($x == 'left') { |
|
74 | + $x = 0; |
|
75 | + } elseif ($x == 'center') { |
|
76 | + $x = $imageWidth / 2 - ($watermarkWidth / 2); |
|
77 | + } elseif ($x == 'right') { |
|
78 | + $x = $imageWidth - $watermarkWidth; |
|
79 | + } |
|
80 | + return intval($x); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Use build-in logic to position the y of watermark |
|
85 | - * |
|
86 | - * @param resource $imageResource |
|
87 | - * @return self |
|
88 | - */ |
|
89 | - public function calculateY($imageResource) |
|
90 | - { |
|
91 | - if (intval($this->_y) === $this->_y) return $this->_y; |
|
83 | + /** |
|
84 | + * Use build-in logic to position the y of watermark |
|
85 | + * |
|
86 | + * @param resource $imageResource |
|
87 | + * @return self |
|
88 | + */ |
|
89 | + public function calculateY($imageResource) |
|
90 | + { |
|
91 | + if (intval($this->_y) === $this->_y) return $this->_y; |
|
92 | 92 | |
93 | - $y = strtolower($this->_y); |
|
93 | + $y = strtolower($this->_y); |
|
94 | 94 | |
95 | - $imageHeight = imagesy($imageResource); |
|
96 | - $watermarkHeight = imagesy($this->GetWatermark()->getImageResource()); |
|
95 | + $imageHeight = imagesy($imageResource); |
|
96 | + $watermarkHeight = imagesy($this->GetWatermark()->getImageResource()); |
|
97 | 97 | |
98 | - if ($y == 'top') { |
|
99 | - $y = 0; |
|
100 | - } elseif ($y == 'center') { |
|
101 | - $y = $imageHeight / 2 - ($watermarkHeight / 2); |
|
102 | - } elseif ($y == 'bottom') { |
|
103 | - $y = $imageHeight - $watermarkHeight; |
|
104 | - } |
|
105 | - return intval($y); |
|
106 | - } |
|
98 | + if ($y == 'top') { |
|
99 | + $y = 0; |
|
100 | + } elseif ($y == 'center') { |
|
101 | + $y = $imageHeight / 2 - ($watermarkHeight / 2); |
|
102 | + } elseif ($y == 'bottom') { |
|
103 | + $y = $imageHeight - $watermarkHeight; |
|
104 | + } |
|
105 | + return intval($y); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Sets the image that will be used as watermark |
|
110 | - * |
|
111 | - * @param Image $image |
|
112 | - * @return Watermark |
|
113 | - */ |
|
114 | - public function SetWatermark(Image $image) |
|
115 | - { |
|
116 | - $this->_watermark = $image; |
|
117 | - return $this; |
|
118 | - } |
|
108 | + /** |
|
109 | + * Sets the image that will be used as watermark |
|
110 | + * |
|
111 | + * @param Image $image |
|
112 | + * @return Watermark |
|
113 | + */ |
|
114 | + public function SetWatermark(Image $image) |
|
115 | + { |
|
116 | + $this->_watermark = $image; |
|
117 | + return $this; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Returns the watermark. |
|
122 | - * Throws an Exception if it's not set or if it's not an \CloudControl\Cms\image\Image |
|
123 | - * @return \images\Image |
|
124 | - * @throws \Exception |
|
125 | - */ |
|
126 | - public function GetWatermark() |
|
127 | - { |
|
128 | - if ($this->_watermark == null) throw new \Exception('A watermark is not set. Please supply a \CloudControl\Cms\image\Image using $this->SetWatermark'); |
|
129 | - return $this->_watermark; |
|
130 | - } |
|
120 | + /** |
|
121 | + * Returns the watermark. |
|
122 | + * Throws an Exception if it's not set or if it's not an \CloudControl\Cms\image\Image |
|
123 | + * @return \images\Image |
|
124 | + * @throws \Exception |
|
125 | + */ |
|
126 | + public function GetWatermark() |
|
127 | + { |
|
128 | + if ($this->_watermark == null) throw new \Exception('A watermark is not set. Please supply a \CloudControl\Cms\image\Image using $this->SetWatermark'); |
|
129 | + return $this->_watermark; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Set the x |
|
134 | - * |
|
135 | - * @param int | string $x |
|
136 | - * @return self |
|
137 | - */ |
|
138 | - public function SetX($x) |
|
139 | - { |
|
140 | - $this->_x = $x; |
|
141 | - return $this; |
|
142 | - } |
|
132 | + /** |
|
133 | + * Set the x |
|
134 | + * |
|
135 | + * @param int | string $x |
|
136 | + * @return self |
|
137 | + */ |
|
138 | + public function SetX($x) |
|
139 | + { |
|
140 | + $this->_x = $x; |
|
141 | + return $this; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Set the y |
|
146 | - * |
|
147 | - * @param int | string $y |
|
148 | - * @return self |
|
149 | - */ |
|
150 | - public function SetY($y) |
|
151 | - { |
|
152 | - $this->_y = $y; |
|
153 | - return $this; |
|
154 | - } |
|
144 | + /** |
|
145 | + * Set the y |
|
146 | + * |
|
147 | + * @param int | string $y |
|
148 | + * @return self |
|
149 | + */ |
|
150 | + public function SetY($y) |
|
151 | + { |
|
152 | + $this->_y = $y; |
|
153 | + return $this; |
|
154 | + } |
|
155 | 155 | |
156 | - public function Execute($imageResource) |
|
157 | - { |
|
158 | - $watermark = $this->GetWatermark(); |
|
159 | - $watermarkWidth = imagesx($watermark->getImageResource()); |
|
160 | - $watermarkHeight = imagesy($watermark->getImageResource()); |
|
156 | + public function Execute($imageResource) |
|
157 | + { |
|
158 | + $watermark = $this->GetWatermark(); |
|
159 | + $watermarkWidth = imagesx($watermark->getImageResource()); |
|
160 | + $watermarkHeight = imagesy($watermark->getImageResource()); |
|
161 | 161 | |
162 | - $x = $this->calculateX($imageResource); |
|
163 | - $y = $this->calculateY($imageResource); |
|
162 | + $x = $this->calculateX($imageResource); |
|
163 | + $y = $this->calculateY($imageResource); |
|
164 | 164 | |
165 | - $imageWidth = imagesx($imageResource); |
|
166 | - $imageHeight = imagesy($imageResource); |
|
165 | + $imageWidth = imagesx($imageResource); |
|
166 | + $imageHeight = imagesy($imageResource); |
|
167 | 167 | |
168 | - $new = imagecreatetruecolor($imageWidth, $imageHeight); |
|
168 | + $new = imagecreatetruecolor($imageWidth, $imageHeight); |
|
169 | 169 | |
170 | - // Preserve transparency of the image |
|
171 | - imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
172 | - imagealphablending($new, false); |
|
173 | - imagesavealpha($new, true); |
|
170 | + // Preserve transparency of the image |
|
171 | + imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
172 | + imagealphablending($new, false); |
|
173 | + imagesavealpha($new, true); |
|
174 | 174 | |
175 | - // Preserve transparency of the watermark |
|
176 | - imagecolortransparent($watermark->getImageResource(), imagecolorallocatealpha($watermark->getImageResource(), 0, 0, 0, 127)); |
|
177 | - imagealphablending($watermark->getImageResource(), false); |
|
178 | - imagesavealpha($watermark->getImageResource(), true); |
|
175 | + // Preserve transparency of the watermark |
|
176 | + imagecolortransparent($watermark->getImageResource(), imagecolorallocatealpha($watermark->getImageResource(), 0, 0, 0, 127)); |
|
177 | + imagealphablending($watermark->getImageResource(), false); |
|
178 | + imagesavealpha($watermark->getImageResource(), true); |
|
179 | 179 | |
180 | - imagealphablending($new, true); |
|
181 | - imagealphablending($watermark->getImageResource(), true); |
|
180 | + imagealphablending($new, true); |
|
181 | + imagealphablending($watermark->getImageResource(), true); |
|
182 | 182 | |
183 | - imagecopy($new, $imageResource, 0, 0, 0, 0, $imageWidth, $imageHeight); |
|
184 | - imagecopymerge($new, $watermark->getImageResource(), $x, $y, 0, 0, $watermarkWidth, $watermarkHeight, $this->_transparency); |
|
183 | + imagecopy($new, $imageResource, 0, 0, 0, 0, $imageWidth, $imageHeight); |
|
184 | + imagecopymerge($new, $watermark->getImageResource(), $x, $y, 0, 0, $watermarkWidth, $watermarkHeight, $this->_transparency); |
|
185 | 185 | |
186 | - return $new; |
|
187 | - } |
|
188 | - } |
|
186 | + return $new; |
|
187 | + } |
|
188 | + } |
|
189 | 189 | } |
190 | 190 | \ No newline at end of file |
@@ -63,7 +63,9 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function calculateX($imageResource) |
65 | 65 | { |
66 | - if (intval($this->_x) === $this->_x) return $this->_x; |
|
66 | + if (intval($this->_x) === $this->_x) { |
|
67 | + return $this->_x; |
|
68 | + } |
|
67 | 69 | |
68 | 70 | $x = strtolower($this->_x); |
69 | 71 | |
@@ -88,7 +90,9 @@ discard block |
||
88 | 90 | */ |
89 | 91 | public function calculateY($imageResource) |
90 | 92 | { |
91 | - if (intval($this->_y) === $this->_y) return $this->_y; |
|
93 | + if (intval($this->_y) === $this->_y) { |
|
94 | + return $this->_y; |
|
95 | + } |
|
92 | 96 | |
93 | 97 | $y = strtolower($this->_y); |
94 | 98 | |
@@ -125,7 +129,9 @@ discard block |
||
125 | 129 | */ |
126 | 130 | public function GetWatermark() |
127 | 131 | { |
128 | - if ($this->_watermark == null) throw new \Exception('A watermark is not set. Please supply a \CloudControl\Cms\image\Image using $this->SetWatermark'); |
|
132 | + if ($this->_watermark == null) { |
|
133 | + throw new \Exception('A watermark is not set. Please supply a \CloudControl\Cms\image\Image using $this->SetWatermark'); |
|
134 | + } |
|
129 | 135 | return $this->_watermark; |
130 | 136 | } |
131 | 137 |
@@ -14,114 +14,114 @@ |
||
14 | 14 | use CloudControl\Cms\images\IMethod; |
15 | 15 | |
16 | 16 | class Crop extends IMethod |
17 | - { |
|
18 | - protected $_width; |
|
19 | - protected $_height; |
|
20 | - protected $_x; |
|
21 | - protected $_y; |
|
17 | + { |
|
18 | + protected $_width; |
|
19 | + protected $_height; |
|
20 | + protected $_x; |
|
21 | + protected $_y; |
|
22 | 22 | |
23 | - protected $_destWidth; |
|
24 | - protected $_destHeight; |
|
25 | - protected $_destX = 0.0; |
|
26 | - protected $_destY = 0.0; |
|
23 | + protected $_destWidth; |
|
24 | + protected $_destHeight; |
|
25 | + protected $_destX = 0.0; |
|
26 | + protected $_destY = 0.0; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var null|array |
|
30 | - */ |
|
31 | - protected $_backgroundColor = null; |
|
28 | + /** |
|
29 | + * @var null|array |
|
30 | + */ |
|
31 | + protected $_backgroundColor = null; |
|
32 | 32 | |
33 | - public function init() |
|
34 | - {} |
|
33 | + public function init() |
|
34 | + {} |
|
35 | 35 | |
36 | - /** |
|
37 | - * Set the width |
|
38 | - * |
|
39 | - * @param int $width |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - public function SetWidth($width) |
|
43 | - { |
|
44 | - $this->_width = intval($width); |
|
45 | - $this->_destWidth = intval($width); |
|
46 | - return $this; |
|
47 | - } |
|
36 | + /** |
|
37 | + * Set the width |
|
38 | + * |
|
39 | + * @param int $width |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + public function SetWidth($width) |
|
43 | + { |
|
44 | + $this->_width = intval($width); |
|
45 | + $this->_destWidth = intval($width); |
|
46 | + return $this; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Set the height |
|
51 | - * |
|
52 | - * @param int $height |
|
53 | - * @return self |
|
54 | - */ |
|
55 | - public function SetHeight($height) |
|
56 | - { |
|
57 | - $this->_height = intval($height); |
|
58 | - $this->_destHeight = intval($height); |
|
59 | - return $this; |
|
60 | - } |
|
49 | + /** |
|
50 | + * Set the height |
|
51 | + * |
|
52 | + * @param int $height |
|
53 | + * @return self |
|
54 | + */ |
|
55 | + public function SetHeight($height) |
|
56 | + { |
|
57 | + $this->_height = intval($height); |
|
58 | + $this->_destHeight = intval($height); |
|
59 | + return $this; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Set the x |
|
64 | - * |
|
65 | - * @param int $x |
|
66 | - * @return self |
|
67 | - */ |
|
68 | - public function SetX($x) |
|
69 | - { |
|
70 | - $this->_x = $x; |
|
71 | - return $this; |
|
72 | - } |
|
62 | + /** |
|
63 | + * Set the x |
|
64 | + * |
|
65 | + * @param int $x |
|
66 | + * @return self |
|
67 | + */ |
|
68 | + public function SetX($x) |
|
69 | + { |
|
70 | + $this->_x = $x; |
|
71 | + return $this; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Set the y |
|
76 | - * |
|
77 | - * @param int $y |
|
78 | - * @return self |
|
79 | - */ |
|
80 | - public function SetY($y) |
|
81 | - { |
|
82 | - $this->_y = $y; |
|
83 | - return $this; |
|
84 | - } |
|
74 | + /** |
|
75 | + * Set the y |
|
76 | + * |
|
77 | + * @param int $y |
|
78 | + * @return self |
|
79 | + */ |
|
80 | + public function SetY($y) |
|
81 | + { |
|
82 | + $this->_y = $y; |
|
83 | + return $this; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * If neccesary, fill the background color |
|
88 | - * with this color |
|
89 | - * |
|
90 | - * @param int $r Red |
|
91 | - * @param int $g Green |
|
92 | - * @param int $b Blue |
|
93 | - * |
|
94 | - * @return $this |
|
95 | - */ |
|
96 | - public function FillBackground($r, $g, $b) |
|
97 | - { |
|
98 | - $this->_backgroundColor = array(intval($r), intval($g), intval($b)); |
|
99 | - return $this; |
|
100 | - } |
|
86 | + /** |
|
87 | + * If neccesary, fill the background color |
|
88 | + * with this color |
|
89 | + * |
|
90 | + * @param int $r Red |
|
91 | + * @param int $g Green |
|
92 | + * @param int $b Blue |
|
93 | + * |
|
94 | + * @return $this |
|
95 | + */ |
|
96 | + public function FillBackground($r, $g, $b) |
|
97 | + { |
|
98 | + $this->_backgroundColor = array(intval($r), intval($g), intval($b)); |
|
99 | + return $this; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param resource $imageResource |
|
104 | - * |
|
105 | - * @return resource |
|
106 | - */ |
|
107 | - public function Execute($imageResource) |
|
108 | - { |
|
109 | - // Create the new image |
|
110 | - $new = imagecreatetruecolor($this->_width, $this->_height); |
|
102 | + /** |
|
103 | + * @param resource $imageResource |
|
104 | + * |
|
105 | + * @return resource |
|
106 | + */ |
|
107 | + public function Execute($imageResource) |
|
108 | + { |
|
109 | + // Create the new image |
|
110 | + $new = imagecreatetruecolor($this->_width, $this->_height); |
|
111 | 111 | |
112 | - if ($this->_backgroundColor !== null) { |
|
113 | - $fill = imagecolorallocate($new, $this->_backgroundColor[0], $this->_backgroundColor[1], $this->_backgroundColor[2]); |
|
114 | - imagefill($new, 0, 0, $fill); |
|
115 | - } |
|
112 | + if ($this->_backgroundColor !== null) { |
|
113 | + $fill = imagecolorallocate($new, $this->_backgroundColor[0], $this->_backgroundColor[1], $this->_backgroundColor[2]); |
|
114 | + imagefill($new, 0, 0, $fill); |
|
115 | + } |
|
116 | 116 | |
117 | - // Preserve transparency |
|
118 | - imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
117 | + // Preserve transparency |
|
118 | + imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
119 | 119 | imagealphablending($new, false); |
120 | 120 | imagesavealpha($new, true); |
121 | 121 | |
122 | - imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $this->_destWidth, $this->_destHeight); |
|
122 | + imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $this->_destWidth, $this->_destHeight); |
|
123 | 123 | |
124 | - return $new; |
|
125 | - } |
|
126 | - } |
|
124 | + return $new; |
|
125 | + } |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | \ No newline at end of file |
@@ -10,62 +10,62 @@ |
||
10 | 10 | |
11 | 11 | namespace CloudControl\Cms\images\methods |
12 | 12 | { |
13 | - class SmartCrop extends Crop |
|
14 | - { |
|
15 | - /** |
|
16 | - * Use build-in logic to position the smartcrop |
|
17 | - * |
|
18 | - * @param string $x |
|
19 | - * @param string $y |
|
20 | - * @return self |
|
21 | - */ |
|
22 | - public function SetPosition($x, $y) |
|
23 | - { |
|
24 | - $this->SetX($x); |
|
25 | - $this->SetY($y); |
|
26 | - return $this; |
|
27 | - } |
|
13 | + class SmartCrop extends Crop |
|
14 | + { |
|
15 | + /** |
|
16 | + * Use build-in logic to position the smartcrop |
|
17 | + * |
|
18 | + * @param string $x |
|
19 | + * @param string $y |
|
20 | + * @return self |
|
21 | + */ |
|
22 | + public function SetPosition($x, $y) |
|
23 | + { |
|
24 | + $this->SetX($x); |
|
25 | + $this->SetY($y); |
|
26 | + return $this; |
|
27 | + } |
|
28 | 28 | |
29 | - public function Execute($imageResource) |
|
30 | - { |
|
31 | - // Define the origial width and height |
|
32 | - $originalWidth = imagesx($imageResource); |
|
33 | - $originalHeight = imagesy($imageResource); |
|
29 | + public function Execute($imageResource) |
|
30 | + { |
|
31 | + // Define the origial width and height |
|
32 | + $originalWidth = imagesx($imageResource); |
|
33 | + $originalHeight = imagesy($imageResource); |
|
34 | 34 | |
35 | - // Define the ratios |
|
36 | - $wRatio = $originalWidth / $this->_width; |
|
37 | - $hRatio = $originalHeight / $this->_height; |
|
35 | + // Define the ratios |
|
36 | + $wRatio = $originalWidth / $this->_width; |
|
37 | + $hRatio = $originalHeight / $this->_height; |
|
38 | 38 | |
39 | - // Define which ratio will be used, depending on which is the biggest side |
|
40 | - $ratio = $wRatio < $hRatio ? $wRatio : $hRatio; |
|
41 | - if ($ratio < 1) $ratio = 1; |
|
39 | + // Define which ratio will be used, depending on which is the biggest side |
|
40 | + $ratio = $wRatio < $hRatio ? $wRatio : $hRatio; |
|
41 | + if ($ratio < 1) $ratio = 1; |
|
42 | 42 | |
43 | - // Calculate the destination width, height, x and y |
|
44 | - $this->_destWidth = $originalWidth / $ratio; |
|
45 | - $this->_destHeight = $originalHeight / $ratio; |
|
46 | - $this->_destX = ($this->_width - $this->_destWidth) / 2; |
|
47 | - $this->_destY = ($this->_height - $this->_destHeight) / 2; |
|
43 | + // Calculate the destination width, height, x and y |
|
44 | + $this->_destWidth = $originalWidth / $ratio; |
|
45 | + $this->_destHeight = $originalHeight / $ratio; |
|
46 | + $this->_destX = ($this->_width - $this->_destWidth) / 2; |
|
47 | + $this->_destY = ($this->_height - $this->_destHeight) / 2; |
|
48 | 48 | |
49 | - // Define the origial width and height |
|
50 | - $originalWidth = imagesx($imageResource); |
|
51 | - $originalHeight = imagesy($imageResource); |
|
49 | + // Define the origial width and height |
|
50 | + $originalWidth = imagesx($imageResource); |
|
51 | + $originalHeight = imagesy($imageResource); |
|
52 | 52 | |
53 | - // Create the new image |
|
54 | - $new = imagecreatetruecolor($this->_width, $this->_height); |
|
53 | + // Create the new image |
|
54 | + $new = imagecreatetruecolor($this->_width, $this->_height); |
|
55 | 55 | |
56 | - if ($this->_backgroundColor !== null) { |
|
57 | - $fill = imagecolorallocate($new, $this->_backgroundColor[0], $this->_backgroundColor[1], $this->_backgroundColor[2]); |
|
58 | - imagefill($new, 0, 0, $fill); |
|
59 | - } |
|
56 | + if ($this->_backgroundColor !== null) { |
|
57 | + $fill = imagecolorallocate($new, $this->_backgroundColor[0], $this->_backgroundColor[1], $this->_backgroundColor[2]); |
|
58 | + imagefill($new, 0, 0, $fill); |
|
59 | + } |
|
60 | 60 | |
61 | - // Preserve transparency |
|
62 | - imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
61 | + // Preserve transparency |
|
62 | + imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
63 | 63 | imagealphablending($new, false); |
64 | 64 | imagesavealpha($new, true); |
65 | 65 | |
66 | - imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
|
66 | + imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
|
67 | 67 | |
68 | - return $new; |
|
69 | - } |
|
70 | - } |
|
68 | + return $new; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | } |
72 | 72 | \ No newline at end of file |
@@ -38,7 +38,9 @@ |
||
38 | 38 | |
39 | 39 | // Define which ratio will be used, depending on which is the biggest side |
40 | 40 | $ratio = $wRatio < $hRatio ? $wRatio : $hRatio; |
41 | - if ($ratio < 1) $ratio = 1; |
|
41 | + if ($ratio < 1) { |
|
42 | + $ratio = 1; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | // Calculate the destination width, height, x and y |
44 | 46 | $this->_destWidth = $originalWidth / $ratio; |
@@ -12,18 +12,18 @@ |
||
12 | 12 | use CloudControl\Cms\images\IMethod; |
13 | 13 | |
14 | 14 | class Grayscale extends IMethod |
15 | - { |
|
16 | - public function Execute($imageResource) |
|
17 | - { |
|
18 | - // Preserve transparency |
|
19 | - imagecolortransparent($imageResource, imagecolorallocatealpha($imageResource, 0, 0, 0, 127)); |
|
20 | - imagealphablending($imageResource, false); |
|
21 | - imagesavealpha($imageResource, true); |
|
15 | + { |
|
16 | + public function Execute($imageResource) |
|
17 | + { |
|
18 | + // Preserve transparency |
|
19 | + imagecolortransparent($imageResource, imagecolorallocatealpha($imageResource, 0, 0, 0, 127)); |
|
20 | + imagealphablending($imageResource, false); |
|
21 | + imagesavealpha($imageResource, true); |
|
22 | 22 | |
23 | - // Make grayscale |
|
24 | - imagefilter($imageResource, IMG_FILTER_GRAYSCALE); |
|
23 | + // Make grayscale |
|
24 | + imagefilter($imageResource, IMG_FILTER_GRAYSCALE); |
|
25 | 25 | |
26 | - return $imageResource; |
|
27 | - } |
|
28 | - } |
|
26 | + return $imageResource; |
|
27 | + } |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | <div class="form-element"> |
13 | 13 | <label for="<?=$field->slug?>"><?=$field->title?></label> |
14 | 14 | <? if (isset($dynamicBrick)) : |
15 | - $fieldSlug = $field->slug; |
|
16 | - $value = isset($dynamicBrick->fields->$fieldSlug) ? current($dynamicBrick->fields->$fieldSlug) : ''; |
|
17 | - else : |
|
18 | - $value = ''; |
|
19 | - endif ?> |
|
15 | + $fieldSlug = $field->slug; |
|
16 | + $value = isset($dynamicBrick->fields->$fieldSlug) ? current($dynamicBrick->fields->$fieldSlug) : ''; |
|
17 | + else : |
|
18 | + $value = ''; |
|
19 | + endif ?> |
|
20 | 20 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
21 | 21 | <ul class="grid-wrapper sortable"> |
22 | 22 | <li class="grid-container"> |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | </div> |
45 | 45 | </li> |
46 | 46 | <? if (isset($dynamicBrick)) : |
47 | - $fieldSlug = $field->slug; |
|
48 | - $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
49 | - array_shift($iterable); |
|
50 | - ?> |
|
47 | + $fieldSlug = $field->slug; |
|
48 | + $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
49 | + array_shift($iterable); |
|
50 | + ?> |
|
51 | 51 | <? foreach ($iterable as $value) : ?> |
52 | 52 | |
53 | 53 | <li class="grid-container"> |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | <a class="btn js-addmultiple">+</a> |
71 | 71 | <? elseif ($field->multiple == true) : ?> |
72 | 72 | <? if (isset($dynamicBrick)) : |
73 | - $fieldSlug = $field->slug; |
|
74 | - $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
75 | - array_shift($iterable); |
|
76 | - ?> |
|
73 | + $fieldSlug = $field->slug; |
|
74 | + $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
75 | + array_shift($iterable); |
|
76 | + ?> |
|
77 | 77 | <? foreach ($iterable as $value) : ?> |
78 | 78 | |
79 | 79 | <li> |
@@ -14,8 +14,10 @@ |
||
14 | 14 | <? if (isset($dynamicBrick)) : |
15 | 15 | $fieldSlug = $field->slug; |
16 | 16 | $value = isset($dynamicBrick->fields->$fieldSlug) ? current($dynamicBrick->fields->$fieldSlug) : ''; |
17 | - else : |
|
17 | + else { |
|
18 | + : |
|
18 | 19 | $value = ''; |
20 | + } |
|
19 | 21 | endif ?> |
20 | 22 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
21 | 23 | <ul class="grid-wrapper sortable"> |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | </div> |
64 | 64 | </div> |
65 | 65 | </li> |
66 | - <?$value='';?> |
|
66 | + <?$value = ''; ?> |
|
67 | 67 | <? endforeach ?> |
68 | 68 | <? endif ?> |
69 | 69 | </ul> |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
84 | 84 | </div> |
85 | 85 | </li> |
86 | - <?$value='';?> |
|
86 | + <?$value = ''; ?> |
|
87 | 87 | <? endforeach ?> |
88 | 88 | <? endif ?> |
89 | 89 | </div> |
@@ -92,5 +92,5 @@ discard block |
||
92 | 92 | <a class="btn js-addrtemultiple">+</a> |
93 | 93 | <? endif ?> |
94 | 94 | </div> |
95 | - <?$value='';?> |
|
95 | + <?$value = ''; ?> |
|
96 | 96 | <? endforeach ?> |
@@ -31,26 +31,26 @@ |
||
31 | 31 | <div class="documentActions grid-box-2"> |
32 | 32 | <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?> |
33 | 33 | <? renderAction('Publish', |
34 | - 'publish', |
|
35 | - $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
36 | - 'check'); ?> |
|
34 | + 'publish', |
|
35 | + $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
36 | + 'check'); ?> |
|
37 | 37 | <? endif ?> |
38 | 38 | <? if ($document->state == 'published') : ?> |
39 | 39 | <? renderAction('Unpublish', |
40 | - 'unpublish', |
|
41 | - $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug, |
|
42 | - 'times'); ?> |
|
40 | + 'unpublish', |
|
41 | + $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug, |
|
42 | + 'times'); ?> |
|
43 | 43 | <? endif ?> |
44 | 44 | <? renderAction('Edit', |
45 | - '', |
|
46 | - $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug, |
|
47 | - 'pencil'); ?> |
|
45 | + '', |
|
46 | + $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug, |
|
47 | + 'pencil'); ?> |
|
48 | 48 | <? if ($document->state == 'unpublished') : ?> |
49 | 49 | <? renderAction('Delete', |
50 | - 'error', |
|
51 | - $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
|
52 | - 'trash', |
|
53 | - 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
|
50 | + 'error', |
|
51 | + $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
|
52 | + 'trash', |
|
53 | + 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
|
54 | 54 | <? endif ?> |
55 | 55 | </div> |
56 | 56 | <? } ?> |