@@ -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 |
@@ -9,232 +9,232 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace CloudControl\Cms\images { |
| 12 | - class Image |
|
| 13 | - { |
|
| 14 | - private $_imageResource; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Load the a image resource into $this->_imageResource |
|
| 18 | - * automagically :-) |
|
| 19 | - * |
|
| 20 | - * @param resource | string | path |
|
| 21 | - * |
|
| 22 | - * @throws \Exception |
|
| 23 | - */ |
|
| 24 | - public function loadImage($imageContainer) |
|
| 25 | - { |
|
| 26 | - if (is_resource($imageContainer) && get_resource_type($imageContainer) === 'gd') { |
|
| 27 | - $this->_imageResource = $imageContainer; |
|
| 28 | - } elseif (is_string($imageContainer) && file_exists($imageContainer)) { |
|
| 29 | - if ($this->getImageMimeType($imageContainer) == IMAGETYPE_BMP) { |
|
| 30 | - $this->_imageResource = $this->createImageFromBmp($imageContainer); |
|
| 31 | - } else { |
|
| 32 | - $imageContent = file_get_contents($imageContainer); |
|
| 33 | - $this->_imageResource = imagecreatefromstring($imageContent); |
|
| 34 | - } |
|
| 35 | - } elseif (is_string($imageContainer)) { |
|
| 36 | - $this->_imageResource = imagecreatefromstring($imageContainer); |
|
| 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>'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Saves the image to a file |
|
| 44 | - * |
|
| 45 | - * @param string $path |
|
| 46 | - * @param int $mimeTypeConstantValue |
|
| 47 | - * @param int $quality |
|
| 48 | - * @param null $imageResource If no resource is given, uses $this->_imageResource |
|
| 49 | - * |
|
| 50 | - * @return bool |
|
| 51 | - * @throws \Exception |
|
| 52 | - */ |
|
| 53 | - public function saveImage($path, $mimeTypeConstantValue, $quality = 100, $imageResource = null) |
|
| 54 | - { |
|
| 55 | - if ($imageResource == null) { |
|
| 56 | - $imageResource = $this->getImageResource(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if ($mimeTypeConstantValue == IMAGETYPE_GIF) { |
|
| 60 | - return imagegif($imageResource, $path); |
|
| 61 | - } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
| 62 | - return imagejpeg($imageResource, $path, $quality); |
|
| 63 | - } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
|
| 64 | - return imagepng($imageResource, $path, (intval($quality / 10) - 1)); |
|
| 65 | - } else { |
|
| 66 | - throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns either the Mime-Type Constant value |
|
| 72 | - * or the default extension for the detected mime-type; |
|
| 73 | - * |
|
| 74 | - * @see http://www.php.net/manual/en/function.image-type-to-mime-type.php |
|
| 75 | - * |
|
| 76 | - * @param string $imagePath |
|
| 77 | - * @param bool $getExtension |
|
| 78 | - * |
|
| 79 | - * @return bool|int|string |
|
| 80 | - */ |
|
| 81 | - public function getImageMimeType($imagePath, $getExtension = false) |
|
| 82 | - { |
|
| 83 | - if (function_exists('exif_imagetype')) { |
|
| 84 | - $exif = exif_imagetype($imagePath); |
|
| 85 | - } else { |
|
| 86 | - if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false) { |
|
| 87 | - $exif = $type; |
|
| 88 | - } else { |
|
| 89 | - $exif = false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $getExtension ? image_type_to_extension($exif) : $exif; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Create Image resource from Bitmap |
|
| 98 | - * |
|
| 99 | - * @see http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214 |
|
| 100 | - * @author alexander at alexauto dot nl |
|
| 101 | - * |
|
| 102 | - * @param string $pathToBitmapFile |
|
| 103 | - * |
|
| 104 | - * @return resource |
|
| 105 | - */ |
|
| 106 | - public function createImageFromBmp($pathToBitmapFile) |
|
| 107 | - { |
|
| 108 | - $bitmapFileData = $this->getBitmapFileData($pathToBitmapFile); |
|
| 109 | - |
|
| 110 | - $temp = unpack("H*", $bitmapFileData); |
|
| 111 | - $hex = $temp[1]; |
|
| 112 | - $header = substr($hex, 0, 108); |
|
| 113 | - list($width, $height) = $this->calculateWidthAndHeight($header); |
|
| 114 | - |
|
| 115 | - // Define starting X and Y |
|
| 116 | - $x = 0; |
|
| 117 | - $y = 1; |
|
| 118 | - |
|
| 119 | - $image = imagecreatetruecolor($width, $height); |
|
| 120 | - |
|
| 121 | - // Grab the body from the image |
|
| 122 | - $body = substr($hex, 108); |
|
| 123 | - |
|
| 124 | - // Calculate if padding at the end-line is needed. Divided by two to keep overview. 1 byte = 2 HEX-chars |
|
| 125 | - $bodySize = (strlen($body) / 2); |
|
| 126 | - $headerSize = ($width * $height); |
|
| 127 | - |
|
| 128 | - // Use end-line padding? Only when needed |
|
| 129 | - $usePadding = ($bodySize > ($headerSize * 3) + 4); |
|
| 130 | - $this->loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image); |
|
| 131 | - |
|
| 132 | - unset($body); |
|
| 133 | - |
|
| 134 | - return $image; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Returns the image resource |
|
| 139 | - * @return resource |
|
| 140 | - * @throws \Exception |
|
| 141 | - */ |
|
| 142 | - final public function getImageResource() |
|
| 143 | - { |
|
| 144 | - if (is_resource($this->_imageResource) && get_resource_type($this->_imageResource) === 'gd') { |
|
| 145 | - return $this->_imageResource; |
|
| 146 | - } else { |
|
| 147 | - throw new \Exception('Image resource is not set. Use $this->LoadImage to load an image into the resource'); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param $pathToBitmapFile |
|
| 153 | - * |
|
| 154 | - * @return string |
|
| 155 | - */ |
|
| 156 | - private function getBitmapFileData($pathToBitmapFile) |
|
| 157 | - { |
|
| 158 | - $fileHandle = fopen($pathToBitmapFile, "rb"); |
|
| 159 | - $bitmapFileData = fread($fileHandle, 10); |
|
| 160 | - while (!feof($fileHandle) && ($bitmapFileData <> "")) { |
|
| 161 | - $bitmapFileData .= fread($fileHandle, 1024); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $bitmapFileData; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param $header |
|
| 169 | - * |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - private function calculateWidthAndHeight($header) |
|
| 173 | - { |
|
| 174 | - $width = null; |
|
| 175 | - $height = null; |
|
| 176 | - |
|
| 177 | - // Structure: http://www.fastgraph.com/help/bmp_header_format.html |
|
| 178 | - if (substr($header, 0, 4) == "424d") { |
|
| 179 | - // Cut it in parts of 2 bytes |
|
| 180 | - $header_parts = str_split($header, 2); |
|
| 181 | - // Get the width 4 bytes |
|
| 182 | - $width = hexdec($header_parts[19] . $header_parts[18]); |
|
| 183 | - // Get the height 4 bytes |
|
| 184 | - $height = hexdec($header_parts[23] . $header_parts[22]); |
|
| 185 | - // Unset the header params |
|
| 186 | - unset($header_parts); |
|
| 187 | - |
|
| 188 | - return array($width, $height); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return array($width, $height); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Loop through the data in the body of the bitmap |
|
| 196 | - * file and calculate each individual pixel based on the |
|
| 197 | - * bytes |
|
| 198 | - * @param $bodySize |
|
| 199 | - * @param $x |
|
| 200 | - * @param $width |
|
| 201 | - * @param $usePadding |
|
| 202 | - * @param $y |
|
| 203 | - * @param $height |
|
| 204 | - * @param $body |
|
| 205 | - * @param $image |
|
| 206 | - */ |
|
| 207 | - private function loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image) |
|
| 208 | - { |
|
| 12 | + class Image |
|
| 13 | + { |
|
| 14 | + private $_imageResource; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Load the a image resource into $this->_imageResource |
|
| 18 | + * automagically :-) |
|
| 19 | + * |
|
| 20 | + * @param resource | string | path |
|
| 21 | + * |
|
| 22 | + * @throws \Exception |
|
| 23 | + */ |
|
| 24 | + public function loadImage($imageContainer) |
|
| 25 | + { |
|
| 26 | + if (is_resource($imageContainer) && get_resource_type($imageContainer) === 'gd') { |
|
| 27 | + $this->_imageResource = $imageContainer; |
|
| 28 | + } elseif (is_string($imageContainer) && file_exists($imageContainer)) { |
|
| 29 | + if ($this->getImageMimeType($imageContainer) == IMAGETYPE_BMP) { |
|
| 30 | + $this->_imageResource = $this->createImageFromBmp($imageContainer); |
|
| 31 | + } else { |
|
| 32 | + $imageContent = file_get_contents($imageContainer); |
|
| 33 | + $this->_imageResource = imagecreatefromstring($imageContent); |
|
| 34 | + } |
|
| 35 | + } elseif (is_string($imageContainer)) { |
|
| 36 | + $this->_imageResource = imagecreatefromstring($imageContainer); |
|
| 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>'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Saves the image to a file |
|
| 44 | + * |
|
| 45 | + * @param string $path |
|
| 46 | + * @param int $mimeTypeConstantValue |
|
| 47 | + * @param int $quality |
|
| 48 | + * @param null $imageResource If no resource is given, uses $this->_imageResource |
|
| 49 | + * |
|
| 50 | + * @return bool |
|
| 51 | + * @throws \Exception |
|
| 52 | + */ |
|
| 53 | + public function saveImage($path, $mimeTypeConstantValue, $quality = 100, $imageResource = null) |
|
| 54 | + { |
|
| 55 | + if ($imageResource == null) { |
|
| 56 | + $imageResource = $this->getImageResource(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if ($mimeTypeConstantValue == IMAGETYPE_GIF) { |
|
| 60 | + return imagegif($imageResource, $path); |
|
| 61 | + } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
| 62 | + return imagejpeg($imageResource, $path, $quality); |
|
| 63 | + } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
|
| 64 | + return imagepng($imageResource, $path, (intval($quality / 10) - 1)); |
|
| 65 | + } else { |
|
| 66 | + throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns either the Mime-Type Constant value |
|
| 72 | + * or the default extension for the detected mime-type; |
|
| 73 | + * |
|
| 74 | + * @see http://www.php.net/manual/en/function.image-type-to-mime-type.php |
|
| 75 | + * |
|
| 76 | + * @param string $imagePath |
|
| 77 | + * @param bool $getExtension |
|
| 78 | + * |
|
| 79 | + * @return bool|int|string |
|
| 80 | + */ |
|
| 81 | + public function getImageMimeType($imagePath, $getExtension = false) |
|
| 82 | + { |
|
| 83 | + if (function_exists('exif_imagetype')) { |
|
| 84 | + $exif = exif_imagetype($imagePath); |
|
| 85 | + } else { |
|
| 86 | + if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false) { |
|
| 87 | + $exif = $type; |
|
| 88 | + } else { |
|
| 89 | + $exif = false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $getExtension ? image_type_to_extension($exif) : $exif; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Create Image resource from Bitmap |
|
| 98 | + * |
|
| 99 | + * @see http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214 |
|
| 100 | + * @author alexander at alexauto dot nl |
|
| 101 | + * |
|
| 102 | + * @param string $pathToBitmapFile |
|
| 103 | + * |
|
| 104 | + * @return resource |
|
| 105 | + */ |
|
| 106 | + public function createImageFromBmp($pathToBitmapFile) |
|
| 107 | + { |
|
| 108 | + $bitmapFileData = $this->getBitmapFileData($pathToBitmapFile); |
|
| 109 | + |
|
| 110 | + $temp = unpack("H*", $bitmapFileData); |
|
| 111 | + $hex = $temp[1]; |
|
| 112 | + $header = substr($hex, 0, 108); |
|
| 113 | + list($width, $height) = $this->calculateWidthAndHeight($header); |
|
| 114 | + |
|
| 115 | + // Define starting X and Y |
|
| 116 | + $x = 0; |
|
| 117 | + $y = 1; |
|
| 118 | + |
|
| 119 | + $image = imagecreatetruecolor($width, $height); |
|
| 120 | + |
|
| 121 | + // Grab the body from the image |
|
| 122 | + $body = substr($hex, 108); |
|
| 123 | + |
|
| 124 | + // Calculate if padding at the end-line is needed. Divided by two to keep overview. 1 byte = 2 HEX-chars |
|
| 125 | + $bodySize = (strlen($body) / 2); |
|
| 126 | + $headerSize = ($width * $height); |
|
| 127 | + |
|
| 128 | + // Use end-line padding? Only when needed |
|
| 129 | + $usePadding = ($bodySize > ($headerSize * 3) + 4); |
|
| 130 | + $this->loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image); |
|
| 131 | + |
|
| 132 | + unset($body); |
|
| 133 | + |
|
| 134 | + return $image; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Returns the image resource |
|
| 139 | + * @return resource |
|
| 140 | + * @throws \Exception |
|
| 141 | + */ |
|
| 142 | + final public function getImageResource() |
|
| 143 | + { |
|
| 144 | + if (is_resource($this->_imageResource) && get_resource_type($this->_imageResource) === 'gd') { |
|
| 145 | + return $this->_imageResource; |
|
| 146 | + } else { |
|
| 147 | + throw new \Exception('Image resource is not set. Use $this->LoadImage to load an image into the resource'); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param $pathToBitmapFile |
|
| 153 | + * |
|
| 154 | + * @return string |
|
| 155 | + */ |
|
| 156 | + private function getBitmapFileData($pathToBitmapFile) |
|
| 157 | + { |
|
| 158 | + $fileHandle = fopen($pathToBitmapFile, "rb"); |
|
| 159 | + $bitmapFileData = fread($fileHandle, 10); |
|
| 160 | + while (!feof($fileHandle) && ($bitmapFileData <> "")) { |
|
| 161 | + $bitmapFileData .= fread($fileHandle, 1024); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $bitmapFileData; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param $header |
|
| 169 | + * |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + private function calculateWidthAndHeight($header) |
|
| 173 | + { |
|
| 174 | + $width = null; |
|
| 175 | + $height = null; |
|
| 176 | + |
|
| 177 | + // Structure: http://www.fastgraph.com/help/bmp_header_format.html |
|
| 178 | + if (substr($header, 0, 4) == "424d") { |
|
| 179 | + // Cut it in parts of 2 bytes |
|
| 180 | + $header_parts = str_split($header, 2); |
|
| 181 | + // Get the width 4 bytes |
|
| 182 | + $width = hexdec($header_parts[19] . $header_parts[18]); |
|
| 183 | + // Get the height 4 bytes |
|
| 184 | + $height = hexdec($header_parts[23] . $header_parts[22]); |
|
| 185 | + // Unset the header params |
|
| 186 | + unset($header_parts); |
|
| 187 | + |
|
| 188 | + return array($width, $height); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return array($width, $height); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Loop through the data in the body of the bitmap |
|
| 196 | + * file and calculate each individual pixel based on the |
|
| 197 | + * bytes |
|
| 198 | + * @param $bodySize |
|
| 199 | + * @param $x |
|
| 200 | + * @param $width |
|
| 201 | + * @param $usePadding |
|
| 202 | + * @param $y |
|
| 203 | + * @param $height |
|
| 204 | + * @param $body |
|
| 205 | + * @param $image |
|
| 206 | + */ |
|
| 207 | + private function loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image) |
|
| 208 | + { |
|
| 209 | 209 | // Using a for-loop with index-calculation instead of str_split to avoid large memory consumption |
| 210 | - // Calculate the next DWORD-position in the body |
|
| 211 | - for ($i = 0; $i < $bodySize; $i += 3) { |
|
| 212 | - // Calculate line-ending and padding |
|
| 213 | - if ($x >= $width) { |
|
| 214 | - // If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block |
|
| 215 | - if ($usePadding) { |
|
| 216 | - $i += $width % 4; |
|
| 217 | - } |
|
| 218 | - // Reset horizontal position |
|
| 219 | - $x = 0; |
|
| 220 | - // Raise the height-position (bottom-up) |
|
| 221 | - $y++; |
|
| 222 | - // Reached the image-height? Break the for-loop |
|
| 223 | - if ($y > $height) { |
|
| 224 | - break; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - // Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body |
|
| 228 | - $iPos = $i * 2; |
|
| 229 | - $r = hexdec($body[$iPos + 4] . $body[$iPos + 5]); |
|
| 230 | - $g = hexdec($body[$iPos + 2] . $body[$iPos + 3]); |
|
| 231 | - $b = hexdec($body[$iPos] . $body[$iPos + 1]); |
|
| 232 | - // Calculate and draw the pixel |
|
| 233 | - $color = imagecolorallocate($image, $r, $g, $b); |
|
| 234 | - imagesetpixel($image, $x, $height - $y, $color); |
|
| 235 | - // Raise the horizontal position |
|
| 236 | - $x++; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 210 | + // Calculate the next DWORD-position in the body |
|
| 211 | + for ($i = 0; $i < $bodySize; $i += 3) { |
|
| 212 | + // Calculate line-ending and padding |
|
| 213 | + if ($x >= $width) { |
|
| 214 | + // If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block |
|
| 215 | + if ($usePadding) { |
|
| 216 | + $i += $width % 4; |
|
| 217 | + } |
|
| 218 | + // Reset horizontal position |
|
| 219 | + $x = 0; |
|
| 220 | + // Raise the height-position (bottom-up) |
|
| 221 | + $y++; |
|
| 222 | + // Reached the image-height? Break the for-loop |
|
| 223 | + if ($y > $height) { |
|
| 224 | + break; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + // Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body |
|
| 228 | + $iPos = $i * 2; |
|
| 229 | + $r = hexdec($body[$iPos + 4] . $body[$iPos + 5]); |
|
| 230 | + $g = hexdec($body[$iPos + 2] . $body[$iPos + 3]); |
|
| 231 | + $b = hexdec($body[$iPos] . $body[$iPos + 1]); |
|
| 232 | + // Calculate and draw the pixel |
|
| 233 | + $color = imagecolorallocate($image, $r, $g, $b); |
|
| 234 | + imagesetpixel($image, $x, $height - $y, $color); |
|
| 235 | + // Raise the horizontal position |
|
| 236 | + $x++; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | } |
| 241 | 241 | \ 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 |
@@ -14,73 +14,73 @@ |
||
| 14 | 14 | use CloudControl\Cms\images\IMethod; |
| 15 | 15 | |
| 16 | 16 | class Resize extends IMethod |
| 17 | - { |
|
| 18 | - protected $_width; |
|
| 19 | - protected $_height; |
|
| 20 | - protected $_preserveAspectRatio = true; |
|
| 17 | + { |
|
| 18 | + protected $_width; |
|
| 19 | + protected $_height; |
|
| 20 | + protected $_preserveAspectRatio = true; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Set the width |
|
| 24 | - * |
|
| 25 | - * @param int $width |
|
| 26 | - * @return self |
|
| 27 | - */ |
|
| 28 | - public function SetWidth($width) |
|
| 29 | - { |
|
| 30 | - $this->_width = intval($width); |
|
| 31 | - return $this; |
|
| 32 | - } |
|
| 22 | + /** |
|
| 23 | + * Set the width |
|
| 24 | + * |
|
| 25 | + * @param int $width |
|
| 26 | + * @return self |
|
| 27 | + */ |
|
| 28 | + public function SetWidth($width) |
|
| 29 | + { |
|
| 30 | + $this->_width = intval($width); |
|
| 31 | + return $this; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Set the height |
|
| 36 | - * |
|
| 37 | - * @param int $height |
|
| 38 | - * @return self |
|
| 39 | - */ |
|
| 40 | - public function SetHeight($height) |
|
| 41 | - { |
|
| 42 | - $this->_height = intval($height); |
|
| 43 | - return $this; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Set the height |
|
| 36 | + * |
|
| 37 | + * @param int $height |
|
| 38 | + * @return self |
|
| 39 | + */ |
|
| 40 | + public function SetHeight($height) |
|
| 41 | + { |
|
| 42 | + $this->_height = intval($height); |
|
| 43 | + return $this; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Sets wheter or not the aspect ratio of the original |
|
| 48 | - * image needs to preserved |
|
| 49 | - * |
|
| 50 | - * @param bool $bool |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public function SetPreserveAspectRatio($bool) |
|
| 54 | - { |
|
| 55 | - $this->_preserveAspectRatio = (bool) $bool; |
|
| 56 | - return $this; |
|
| 57 | - } |
|
| 46 | + /** |
|
| 47 | + * Sets wheter or not the aspect ratio of the original |
|
| 48 | + * image needs to preserved |
|
| 49 | + * |
|
| 50 | + * @param bool $bool |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public function SetPreserveAspectRatio($bool) |
|
| 54 | + { |
|
| 55 | + $this->_preserveAspectRatio = (bool) $bool; |
|
| 56 | + return $this; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function Execute($imageResource) |
|
| 60 | - { |
|
| 61 | - // Define the origial width and height |
|
| 62 | - $originalWidth = imagesx($imageResource); |
|
| 63 | - $originalHeight = imagesy($imageResource); |
|
| 59 | + public function Execute($imageResource) |
|
| 60 | + { |
|
| 61 | + // Define the origial width and height |
|
| 62 | + $originalWidth = imagesx($imageResource); |
|
| 63 | + $originalHeight = imagesy($imageResource); |
|
| 64 | 64 | |
| 65 | - // Define the ratio and adjust the width and height |
|
| 66 | - if ($this->_preserveAspectRatio) { |
|
| 67 | - $ratio = min($this->_width/$originalWidth, $this->_height/$originalHeight); |
|
| 68 | - $this->_width = $originalWidth * $ratio; |
|
| 69 | - $this->_height = $originalHeight * $ratio; |
|
| 70 | - } |
|
| 65 | + // Define the ratio and adjust the width and height |
|
| 66 | + if ($this->_preserveAspectRatio) { |
|
| 67 | + $ratio = min($this->_width/$originalWidth, $this->_height/$originalHeight); |
|
| 68 | + $this->_width = $originalWidth * $ratio; |
|
| 69 | + $this->_height = $originalHeight * $ratio; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // Create the new image |
|
| 73 | - $new = imagecreatetruecolor($this->_width, $this->_height); |
|
| 72 | + // Create the new image |
|
| 73 | + $new = imagecreatetruecolor($this->_width, $this->_height); |
|
| 74 | 74 | |
| 75 | - // Preserve transparency |
|
| 76 | - imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
| 77 | - imagealphablending($new, false); |
|
| 78 | - imagesavealpha($new, true); |
|
| 75 | + // Preserve transparency |
|
| 76 | + imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
| 77 | + imagealphablending($new, false); |
|
| 78 | + imagesavealpha($new, true); |
|
| 79 | 79 | |
| 80 | - // Do the actual resizing |
|
| 81 | - imagecopyresampled($new, $imageResource, 0, 0, 0, 0, $this->_width, $this->_height, $originalWidth, $originalHeight); |
|
| 80 | + // Do the actual resizing |
|
| 81 | + imagecopyresampled($new, $imageResource, 0, 0, 0, 0, $this->_width, $this->_height, $originalWidth, $originalHeight); |
|
| 82 | 82 | |
| 83 | - return $new; |
|
| 84 | - } |
|
| 85 | - } |
|
| 83 | + return $new; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |
| 87 | 87 | \ No newline at end of file |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -10,36 +10,36 @@ |
||
| 10 | 10 | |
| 11 | 11 | namespace CloudControl\Cms\images\methods |
| 12 | 12 | { |
| 13 | - class BoxCrop extends Crop |
|
| 14 | - { |
|
| 15 | - /** |
|
| 16 | - * @param resource $imageResource |
|
| 17 | - * @return resource |
|
| 13 | + class BoxCrop extends Crop |
|
| 14 | + { |
|
| 15 | + /** |
|
| 16 | + * @param resource $imageResource |
|
| 17 | + * @return resource |
|
| 18 | 18 | */ |
| 19 | - public function Execute($imageResource) |
|
| 20 | - { |
|
| 21 | - // Define the origial width and height |
|
| 22 | - $originalWidth = imagesx($imageResource); |
|
| 23 | - $originalHeight = imagesy($imageResource); |
|
| 19 | + public function Execute($imageResource) |
|
| 20 | + { |
|
| 21 | + // Define the origial width and height |
|
| 22 | + $originalWidth = imagesx($imageResource); |
|
| 23 | + $originalHeight = imagesy($imageResource); |
|
| 24 | 24 | |
| 25 | - // Define the ratios |
|
| 26 | - $wRatio = $this->_width / $originalWidth; |
|
| 27 | - $hRatio = $this->_height / $originalHeight; |
|
| 25 | + // Define the ratios |
|
| 26 | + $wRatio = $this->_width / $originalWidth; |
|
| 27 | + $hRatio = $this->_height / $originalHeight; |
|
| 28 | 28 | |
| 29 | - // Define which ratio will be used, depending on which is the smallest side |
|
| 30 | - $ratio = min($hRatio, $wRatio); |
|
| 31 | - if($ratio > 1) $ratio = 1; |
|
| 29 | + // Define which ratio will be used, depending on which is the smallest side |
|
| 30 | + $ratio = min($hRatio, $wRatio); |
|
| 31 | + if($ratio > 1) $ratio = 1; |
|
| 32 | 32 | |
| 33 | - // Define sizes |
|
| 34 | - $this->_destWidth = floor($originalWidth * $ratio); |
|
| 35 | - $this->_destHeight = floor($originalHeight * $ratio); |
|
| 33 | + // Define sizes |
|
| 34 | + $this->_destWidth = floor($originalWidth * $ratio); |
|
| 35 | + $this->_destHeight = floor($originalHeight * $ratio); |
|
| 36 | 36 | |
| 37 | - // Define margins |
|
| 38 | - $this->_destX = floor(($this->_width - $this->_destWidth) / 2); |
|
| 39 | - $this->_destY = floor(($this->_height - $this->_destHeight) / 2); |
|
| 37 | + // Define margins |
|
| 38 | + $this->_destX = floor(($this->_width - $this->_destWidth) / 2); |
|
| 39 | + $this->_destY = floor(($this->_height - $this->_destHeight) / 2); |
|
| 40 | 40 | |
| 41 | - // Execute the Crop method with the given parameters |
|
| 42 | - return parent::Execute($imageResource); |
|
| 43 | - } |
|
| 44 | - } |
|
| 41 | + // Execute the Crop method with the given parameters |
|
| 42 | + return parent::Execute($imageResource); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | \ No newline at end of file |