@@ -73,6 +73,7 @@ |
||
73 | 73 | * @see http://www.php.net/manual/en/function.image-type-to-mime-type.php |
74 | 74 | * @param string $imagePath |
75 | 75 | * @param bool $getExtension |
76 | + * @return integer |
|
76 | 77 | */ |
77 | 78 | public function GetImageMimeType($imagePath, $getExtension = false) |
78 | 79 | { |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | $imageContent = file_get_contents($imageContainer); |
33 | 33 | $this->_imageResource = imagecreatefromstring($imageContent); |
34 | 34 | } |
35 | - } elseif(is_string($imageContainer)) { |
|
35 | + } elseif (is_string($imageContainer)) { |
|
36 | 36 | $this->_imageResource = imagecreatefromstring($imageContainer); |
37 | 37 | } else { |
38 | - throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>' . var_export($imageContainer, true) . '</pre>'); |
|
38 | + throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>'.var_export($imageContainer, true).'</pre>'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | |
56 | 56 | if ($mimeTypeConstantValue == IMAGETYPE_GIF) { |
57 | 57 | return imagegif($imageResource, $path); |
58 | - } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
58 | + } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
59 | 59 | return imagejpeg($imageResource, $path, $quality); |
60 | 60 | } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
61 | - return imagepng($imageResource, $path, (intval($quality / 10) -1)); |
|
61 | + return imagepng($imageResource, $path, (intval($quality / 10) - 1)); |
|
62 | 62 | } |
63 | 63 | else { |
64 | 64 | throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | if (function_exists('exif_imagetype')) { |
80 | 80 | $exif = exif_imagetype($imagePath); |
81 | 81 | } else { |
82 | - if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false ) { |
|
82 | + if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false) { |
|
83 | 83 | $exif = $type; |
84 | 84 | } else { |
85 | 85 | $exif = false; |
@@ -99,86 +99,86 @@ discard block |
||
99 | 99 | public function CreateImageFromBmp($p_sFile) |
100 | 100 | { |
101 | 101 | // Load the image into a string |
102 | - $file = fopen($p_sFile,"rb"); |
|
103 | - $read = fread($file,10); |
|
104 | - while(!feof($file)&&($read<>"")) |
|
105 | - $read .= fread($file,1024); |
|
102 | + $file = fopen($p_sFile, "rb"); |
|
103 | + $read = fread($file, 10); |
|
104 | + while (!feof($file) && ($read <> "")) |
|
105 | + $read .= fread($file, 1024); |
|
106 | 106 | |
107 | - $temp = unpack("H*",$read); |
|
108 | - $hex = $temp[1]; |
|
109 | - $header = substr($hex,0,108); |
|
110 | - $width=null; |
|
111 | - $height=null; |
|
107 | + $temp = unpack("H*", $read); |
|
108 | + $hex = $temp[1]; |
|
109 | + $header = substr($hex, 0, 108); |
|
110 | + $width = null; |
|
111 | + $height = null; |
|
112 | 112 | |
113 | 113 | // Process the header |
114 | 114 | // Structure: http://www.fastgraph.com/help/bmp_header_format.html |
115 | - if (substr($header,0,4)=="424d") |
|
115 | + if (substr($header, 0, 4) == "424d") |
|
116 | 116 | { |
117 | 117 | // Cut it in parts of 2 bytes |
118 | - $header_parts = str_split($header,2); |
|
118 | + $header_parts = str_split($header, 2); |
|
119 | 119 | |
120 | 120 | // Get the width 4 bytes |
121 | - $width = hexdec($header_parts[19].$header_parts[18]); |
|
121 | + $width = hexdec($header_parts[19].$header_parts[18]); |
|
122 | 122 | |
123 | 123 | // Get the height 4 bytes |
124 | - $height = hexdec($header_parts[23].$header_parts[22]); |
|
124 | + $height = hexdec($header_parts[23].$header_parts[22]); |
|
125 | 125 | |
126 | 126 | // Unset the header params |
127 | 127 | unset($header_parts); |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Define starting X and Y |
131 | - $x = 0; |
|
132 | - $y = 1; |
|
131 | + $x = 0; |
|
132 | + $y = 1; |
|
133 | 133 | |
134 | 134 | // Create newimage |
135 | - $image = imagecreatetruecolor($width,$height); |
|
135 | + $image = imagecreatetruecolor($width, $height); |
|
136 | 136 | |
137 | 137 | // Grab the body from the image |
138 | - $body = substr($hex,108); |
|
138 | + $body = substr($hex, 108); |
|
139 | 139 | |
140 | 140 | // Calculate if padding at the end-line is needed |
141 | 141 | // Divided by two to keep overview. |
142 | 142 | // 1 byte = 2 HEX-chars |
143 | - $body_size = (strlen($body)/2); |
|
144 | - $header_size = ($width*$height); |
|
143 | + $body_size = (strlen($body) / 2); |
|
144 | + $header_size = ($width * $height); |
|
145 | 145 | |
146 | 146 | // Use end-line padding? Only when needed |
147 | - $usePadding = ($body_size>($header_size*3)+4); |
|
147 | + $usePadding = ($body_size > ($header_size * 3) + 4); |
|
148 | 148 | |
149 | 149 | // Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption |
150 | 150 | // Calculate the next DWORD-position in the body |
151 | - for ($i=0;$i<$body_size;$i+=3) |
|
151 | + for ($i = 0; $i < $body_size; $i += 3) |
|
152 | 152 | { |
153 | 153 | // Calculate line-ending and padding |
154 | - if ($x>=$width) |
|
154 | + if ($x >= $width) |
|
155 | 155 | { |
156 | 156 | // If padding needed, ignore image-padding |
157 | 157 | // Shift i to the ending of the current 32-bit-block |
158 | 158 | if ($usePadding) |
159 | - $i += $width%4; |
|
159 | + $i += $width % 4; |
|
160 | 160 | |
161 | 161 | // Reset horizontal position |
162 | - $x = 0; |
|
162 | + $x = 0; |
|
163 | 163 | |
164 | 164 | // Raise the height-position (bottom-up) |
165 | 165 | $y++; |
166 | 166 | |
167 | 167 | // Reached the image-height? Break the for-loop |
168 | - if ($y>$height) |
|
168 | + if ($y > $height) |
|
169 | 169 | break; |
170 | 170 | } |
171 | 171 | |
172 | 172 | // Calculation of the RGB-pixel (defined as BGR in image-data) |
173 | 173 | // Define $i_pos as absolute position in the body |
174 | - $i_pos = $i*2; |
|
175 | - $r = hexdec($body[$i_pos+4].$body[$i_pos+5]); |
|
176 | - $g = hexdec($body[$i_pos+2].$body[$i_pos+3]); |
|
177 | - $b = hexdec($body[$i_pos].$body[$i_pos+1]); |
|
174 | + $i_pos = $i * 2; |
|
175 | + $r = hexdec($body[$i_pos + 4].$body[$i_pos + 5]); |
|
176 | + $g = hexdec($body[$i_pos + 2].$body[$i_pos + 3]); |
|
177 | + $b = hexdec($body[$i_pos].$body[$i_pos + 1]); |
|
178 | 178 | |
179 | 179 | // Calculate and draw the pixel |
180 | - $color = imagecolorallocate($image,$r,$g,$b); |
|
181 | - imagesetpixel($image,$x,$height-$y,$color); |
|
180 | + $color = imagecolorallocate($image, $r, $g, $b); |
|
181 | + imagesetpixel($image, $x, $height - $y, $color); |
|
182 | 182 | |
183 | 183 | // Raise the horizontal position |
184 | 184 | $x++; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | - * @param $imagePath |
|
28 | + * @param string $imagePath |
|
29 | 29 | * |
30 | 30 | * @return array |
31 | 31 | * @throws \Exception |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | - * @param $imagePath |
|
115 | + * @param string $imagePath |
|
116 | 116 | * @param string $modifier |
117 | 117 | * |
118 | 118 | * @return string |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | } |
48 | 48 | return $returnFileNames; |
49 | 49 | } else { |
50 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
50 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | - public function resize($imagePath='', $width='',$height='') |
|
54 | + public function resize($imagePath = '', $width = '', $height = '') |
|
55 | 55 | { |
56 | - $modifier = '-r' . $width . 'x' . $height; |
|
56 | + $modifier = '-r'.$width.'x'.$height; |
|
57 | 57 | $destination = $this->modifyName($imagePath, $modifier); |
58 | 58 | if (file_exists($imagePath)) { |
59 | 59 | $image = new Image(); |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | $resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80); |
68 | 68 | return basename($destination); |
69 | 69 | } else { |
70 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
70 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - public function smartcrop($imagePath='', $width='',$height='') |
|
74 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
75 | 75 | { |
76 | - $modifier = '-s' . $width . 'x' . $height; |
|
76 | + $modifier = '-s'.$width.'x'.$height; |
|
77 | 77 | $destination = $this->modifyName($imagePath, $modifier); |
78 | 78 | if (file_exists($imagePath)) { |
79 | 79 | $image = new Image(); |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | $resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80); |
88 | 88 | return basename($destination); |
89 | 89 | } else { |
90 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
90 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - public function boxcrop($imagePath='', $width='',$height='') |
|
94 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
95 | 95 | { |
96 | - $modifier = '-b' . $width . 'x' . $height; |
|
96 | + $modifier = '-b'.$width.'x'.$height; |
|
97 | 97 | $destination = $this->modifyName($imagePath, $modifier); |
98 | 98 | if (file_exists($imagePath)) { |
99 | 99 | $image = new Image(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80); |
108 | 108 | return basename($destination); |
109 | 109 | } else { |
110 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
110 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - private function modifyName($imagePath, $modifier='') |
|
120 | + private function modifyName($imagePath, $modifier = '') |
|
121 | 121 | { |
122 | 122 | $filename = basename($imagePath); |
123 | 123 | $path = dirname($imagePath); |
@@ -127,25 +127,25 @@ discard block |
||
127 | 127 | array_pop($fileParts); |
128 | 128 | $fileNameWithoutExtension = implode('-', $fileParts); |
129 | 129 | $fileNameWithoutExtension = slugify($fileNameWithoutExtension); |
130 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
130 | + $filename = $fileNameWithoutExtension.$modifier.'.'.$extension; |
|
131 | 131 | } else { |
132 | 132 | $filename = slugify($filename); |
133 | 133 | } |
134 | 134 | |
135 | - if (file_exists($path . '/' . $filename)) { |
|
135 | + if (file_exists($path.'/'.$filename)) { |
|
136 | 136 | $fileParts = explode('.', $filename); |
137 | 137 | if (count($fileParts) > 1) { |
138 | 138 | $extension = end($fileParts); |
139 | 139 | array_pop($fileParts); |
140 | 140 | $fileNameWithoutExtension = implode('-', $fileParts); |
141 | 141 | $fileNameWithoutExtension .= '-copy'; |
142 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
142 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
143 | 143 | } else { |
144 | 144 | $filename .= '-copy'; |
145 | 145 | } |
146 | - return $this->modifyName($path . '/' . $filename); |
|
146 | + return $this->modifyName($path.'/'.$filename); |
|
147 | 147 | } |
148 | - return $path . '/' . $filename; |
|
148 | + return $path.'/'.$filename; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | private function validateFilename($filename, $path) |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * Use build-in logic to position the x of watermark |
58 | 58 | * |
59 | 59 | * @param string $imageResource |
60 | - * @return self |
|
60 | + * @return integer |
|
61 | 61 | */ |
62 | 62 | protected function calculateX($imageResource) |
63 | 63 | { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * Use build-in logic to position the y of watermark |
83 | 83 | * |
84 | 84 | * @param string $imageResource |
85 | - * @return self |
|
85 | + * @return integer |
|
86 | 86 | */ |
87 | 87 | public function calculateY($imageResource) |
88 | 88 | { |
@@ -131,6 +131,7 @@ discard block |
||
131 | 131 | * Set the x |
132 | 132 | * |
133 | 133 | * @param int | string $x |
134 | + * @param string $x |
|
134 | 135 | * @return self |
135 | 136 | */ |
136 | 137 | public function SetX($x) |
@@ -143,6 +144,7 @@ discard block |
||
143 | 144 | * Set the y |
144 | 145 | * |
145 | 146 | * @param int | string $y |
147 | + * @param string $y |
|
146 | 148 | * @return self |
147 | 149 | */ |
148 | 150 | public function SetY($y) |
@@ -62,8 +62,8 @@ |
||
62 | 62 | |
63 | 63 | // Preserve transparency |
64 | 64 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
65 | - imagealphablending($new, false); |
|
66 | - imagesavealpha($new, true); |
|
65 | + imagealphablending($new, false); |
|
66 | + imagesavealpha($new, true); |
|
67 | 67 | |
68 | 68 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
69 | 69 |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function config() |
67 | 67 | { |
68 | - $configPath = __DIR__ . '/../../config.json'; |
|
68 | + $configPath = __DIR__.'/../../config.json'; |
|
69 | 69 | if (realpath($configPath) !== false) { |
70 | 70 | $json = file_get_contents($configPath); |
71 | 71 | $this->config = json_decode($json); |
72 | 72 | } else { |
73 | - throw new \Exception('Couldn\'t find config file in path ' . $configPath); |
|
73 | + throw new \Exception('Couldn\'t find config file in path '.$configPath); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | private function sitemapMatching($request) |
94 | 94 | { |
95 | 95 | $sitemap = $this->storage->getSitemap(); |
96 | - $relativeUri = '/' . $request::$relativeUri; |
|
96 | + $relativeUri = '/'.$request::$relativeUri; |
|
97 | 97 | |
98 | 98 | foreach ($sitemap as $sitemapItem) { |
99 | 99 | if ($sitemapItem->regex) { |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $template = $sitemapItem->template; |
140 | 140 | $parameters = $sitemapItem->parameters; |
141 | 141 | |
142 | - $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem=null); |
|
142 | + $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem = null); |
|
143 | 143 | |
144 | 144 | $this->matchedSitemapItems[$key]->object->run($this->storage); |
145 | 145 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @return mixed |
155 | 155 | * @throws \Exception |
156 | 156 | */ |
157 | - private function getComponentObject($class='', $template='', $parameters=array(), $matchedSitemapItem) |
|
157 | + private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
|
158 | 158 | { |
159 | - $libraryComponentName = '\\library\\components\\' . $class; |
|
160 | - $userComponentName = '\\components\\' . $class; |
|
159 | + $libraryComponentName = '\\library\\components\\'.$class; |
|
160 | + $userComponentName = '\\components\\'.$class; |
|
161 | 161 | |
162 | 162 | if (\autoLoad($libraryComponentName, false)) { |
163 | 163 | $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
164 | 164 | } elseif (\autoLoad($userComponentName, false)) { |
165 | 165 | $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
166 | 166 | } else { |
167 | - throw new \Exception('Could not load component ' . $class); |
|
167 | + throw new \Exception('Could not load component '.$class); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | if (!$component instanceof Component) { |