@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * The parameter $bigger_size is the bigger dimension (width or height) of calculated sizes. |
| 169 | 169 | * The other dimension (height or width) will be calculated autamaticaly |
| 170 | 170 | * @param integer $bigger_size |
| 171 | - * @return array */ |
|
| 171 | + * @return integer[] */ |
|
| 172 | 172 | |
| 173 | 173 | public function get_prop_size($bigger_size) {
|
| 174 | 174 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * no samo po edno (x ili y) izmerenie |
| 256 | 256 | * @param integer $width |
| 257 | 257 | * @param integer $height |
| 258 | - * @return bool */ |
|
| 258 | + * @return gd */ |
|
| 259 | 259 | |
| 260 | 260 | public function resize_overflow($width, $height) {
|
| 261 | 261 | |
@@ -397,6 +397,12 @@ discard block |
||
| 397 | 397 | return false; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | + /** |
|
| 401 | + * @param integer $x1 |
|
| 402 | + * @param integer $y1 |
|
| 403 | + * @param integer $x2 |
|
| 404 | + * @param integer $y2 |
|
| 405 | + */ |
|
| 400 | 406 | public function imagefilledrectangle($x1, $y1, $x2, $y2, $color) {
|
| 401 | 407 | $color = $this->gd_color($color); |
| 402 | 408 | if ($color === false) return false; |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class gd {
|
|
| 15 | +class gd |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | /** GD resource |
| 18 | 19 | * @var resource */ |
@@ -40,22 +41,23 @@ discard block |
||
| 40 | 41 | * @param mixed $image |
| 41 | 42 | * @return array */ |
| 42 | 43 | |
| 43 | - protected function build_image($image) {
|
|
| 44 | + protected function build_image($image) |
|
| 45 | + { |
|
| 44 | 46 | |
| 45 | - if ($image instanceof gd) {
|
|
| 47 | + if ($image instanceof gd) { |
|
| 46 | 48 | $width = $image->get_width(); |
| 47 | 49 | $height = $image->get_height(); |
| 48 | 50 | $image = $image->get_image(); |
| 49 | 51 | |
| 50 | - } elseif (is_resource($image) && (get_resource_type($image) == "gd")) {
|
|
| 52 | + } elseif (is_resource($image) && (get_resource_type($image) == "gd")) { |
|
| 51 | 53 | $width = @imagesx($image); |
| 52 | 54 | $height = @imagesy($image); |
| 53 | 55 | |
| 54 | - } elseif (is_array($image)) {
|
|
| 56 | + } elseif (is_array($image)) { |
|
| 55 | 57 | $height = $width = end($image); |
| 56 | 58 | $image = imagecreatetruecolor($width, $height); |
| 57 | 59 | |
| 58 | - } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
|
|
| 60 | + } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) { |
|
| 59 | 61 | $image = |
| 60 | 62 | ($type == IMAGETYPE_GIF) ? @imagecreatefromgif($image) : ( |
| 61 | 63 | ($type == IMAGETYPE_WBMP) ? @imagecreatefromwbmp($image) : ( |
@@ -65,8 +67,9 @@ discard block |
||
| 65 | 67 | ($type == IMAGETYPE_XBM) ? @imagecreatefromxbm($image) : false |
| 66 | 68 | ))))); |
| 67 | 69 | |
| 68 | - if ($type == IMAGETYPE_PNG) |
|
| 69 | - imagealphablending($image, false); |
|
| 70 | + if ($type == IMAGETYPE_PNG) { |
|
| 71 | + imagealphablending($image, false); |
|
| 72 | + } |
|
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 75 | $return = ( |
@@ -80,8 +83,9 @@ discard block |
||
| 80 | 83 | ? array($image, $width, $height) |
| 81 | 84 | : false; |
| 82 | 85 | |
| 83 | - if (($return !== false) && isset($type)) |
|
| 84 | - $this->type = $type; |
|
| 86 | + if (($return !== false) && isset($type)) { |
|
| 87 | + $this->type = $type; |
|
| 88 | + } |
|
| 85 | 89 | |
| 86 | 90 | return $return; |
| 87 | 91 | } |
@@ -97,20 +101,22 @@ discard block |
||
| 97 | 101 | * @param integer $bigger_size |
| 98 | 102 | * @return gd */ |
| 99 | 103 | |
| 100 | - public function __construct($image, $bigger_size=null) {
|
|
| 104 | + public function __construct($image, $bigger_size=null) |
|
| 105 | + { |
|
| 101 | 106 | $this->image = $this->width = $this->height = null; |
| 102 | 107 | |
| 103 | 108 | $image_details = $this->build_image($image); |
| 104 | 109 | |
| 105 | - if ($image_details !== false) |
|
| 106 | - list($this->image, $this->width, $this->height) = $image_details; |
|
| 107 | - else |
|
| 108 | - $this->init_error = true; |
|
| 110 | + if ($image_details !== false) { |
|
| 111 | + list($this->image, $this->width, $this->height) = $image_details; |
|
| 112 | + } else { |
|
| 113 | + $this->init_error = true; |
|
| 114 | + } |
|
| 109 | 115 | |
| 110 | 116 | if (!is_null($this->image) && |
| 111 | 117 | !is_null($bigger_size) && |
| 112 | 118 | (preg_match('/^[1-9][0-9]*$/', $bigger_size) !== false)
|
| 113 | - ) {
|
|
| 119 | + ) { |
|
| 114 | 120 | $image = $this->image; |
| 115 | 121 | list($width, $height) = $this->get_prop_size($bigger_size); |
| 116 | 122 | $this->image = imagecreatetruecolor($width, $height); |
@@ -125,21 +131,24 @@ discard block |
||
| 125 | 131 | /** Returns the GD resource |
| 126 | 132 | * @return resource */ |
| 127 | 133 | |
| 128 | - public function get_image() {
|
|
| 134 | + public function get_image() |
|
| 135 | + { |
|
| 129 | 136 | return $this->image; |
| 130 | 137 | } |
| 131 | 138 | |
| 132 | 139 | /** Returns the image width |
| 133 | 140 | * @return integer */ |
| 134 | 141 | |
| 135 | - public function get_width() {
|
|
| 142 | + public function get_width() |
|
| 143 | + { |
|
| 136 | 144 | return $this->width; |
| 137 | 145 | } |
| 138 | 146 | |
| 139 | 147 | /** Returns the image height |
| 140 | 148 | * @return integer */ |
| 141 | 149 | |
| 142 | - public function get_height() {
|
|
| 150 | + public function get_height() |
|
| 151 | + { |
|
| 143 | 152 | return $this->height; |
| 144 | 153 | } |
| 145 | 154 | |
@@ -147,9 +156,12 @@ discard block |
||
| 147 | 156 | * @param integer $resized_height |
| 148 | 157 | * @return integer */ |
| 149 | 158 | |
| 150 | - public function get_prop_width($resized_height) {
|
|
| 159 | + public function get_prop_width($resized_height) |
|
| 160 | + { |
|
| 151 | 161 | $width = intval(($this->width * $resized_height) / $this->height); |
| 152 | - if (!$width) $width = 1; |
|
| 162 | + if (!$width) { |
|
| 163 | + $width = 1; |
|
| 164 | + } |
|
| 153 | 165 | return $width; |
| 154 | 166 | } |
| 155 | 167 | |
@@ -157,9 +169,12 @@ discard block |
||
| 157 | 169 | * @param integer $resized_width |
| 158 | 170 | * @return integer */ |
| 159 | 171 | |
| 160 | - public function get_prop_height($resized_width) {
|
|
| 172 | + public function get_prop_height($resized_width) |
|
| 173 | + { |
|
| 161 | 174 | $height = intval(($this->height * $resized_width) / $this->width); |
| 162 | - if (!$height) $height = 1; |
|
| 175 | + if (!$height) { |
|
| 176 | + $height = 1; |
|
| 177 | + } |
|
| 163 | 178 | return $height; |
| 164 | 179 | } |
| 165 | 180 | |
@@ -169,18 +184,20 @@ discard block |
||
| 169 | 184 | * @param integer $bigger_size |
| 170 | 185 | * @return array */ |
| 171 | 186 | |
| 172 | - public function get_prop_size($bigger_size) {
|
|
| 187 | + public function get_prop_size($bigger_size) |
|
| 188 | + { |
|
| 173 | 189 | |
| 174 | - if ($this->width > $this->height) {
|
|
| 190 | + if ($this->width > $this->height) { |
|
| 175 | 191 | $width = $bigger_size; |
| 176 | 192 | $height = $this->get_prop_height($width); |
| 177 | 193 | |
| 178 | - } elseif ($this->height > $this->width) {
|
|
| 194 | + } elseif ($this->height > $this->width) { |
|
| 179 | 195 | $height = $bigger_size; |
| 180 | 196 | $width = $this->get_prop_width($height); |
| 181 | 197 | |
| 182 | - } else |
|
| 183 | - $width = $height = $bigger_size; |
|
| 198 | + } else { |
|
| 199 | + $width = $height = $bigger_size; |
|
| 200 | + } |
|
| 184 | 201 | |
| 185 | 202 | return array($width, $height); |
| 186 | 203 | } |
@@ -190,9 +207,14 @@ discard block |
||
| 190 | 207 | * @param integer $height |
| 191 | 208 | * @return bool */ |
| 192 | 209 | |
| 193 | - public function resize($width, $height) {
|
|
| 194 | - if (!$width) $width = 1; |
|
| 195 | - if (!$height) $height = 1; |
|
| 210 | + public function resize($width, $height) |
|
| 211 | + { |
|
| 212 | + if (!$width) { |
|
| 213 | + $width = 1; |
|
| 214 | + } |
|
| 215 | + if (!$height) { |
|
| 216 | + $height = 1; |
|
| 217 | + } |
|
| 196 | 218 | return ( |
| 197 | 219 | (false !== ($img = new gd(array($width, $height)))) && |
| 198 | 220 | $img->imagecopyresampled($this) && |
@@ -207,19 +229,20 @@ discard block |
||
| 207 | 229 | * @param mixed $src |
| 208 | 230 | * @return bool */ |
| 209 | 231 | |
| 210 | - public function resize_crop($src) {
|
|
| 232 | + public function resize_crop($src) |
|
| 233 | + { |
|
| 211 | 234 | $image_details = $this->build_image($src); |
| 212 | 235 | |
| 213 | - if ($image_details !== false) {
|
|
| 236 | + if ($image_details !== false) { |
|
| 214 | 237 | list($src, $src_width, $src_height) = $image_details; |
| 215 | 238 | |
| 216 | - if (($src_width / $src_height) > ($this->width / $this->height)) {
|
|
| 239 | + if (($src_width / $src_height) > ($this->width / $this->height)) { |
|
| 217 | 240 | $src_w = $this->get_prop_width($src_height); |
| 218 | 241 | $src_h = $src_height; |
| 219 | 242 | $src_x = intval(($src_width - $src_w) / 2); |
| 220 | 243 | $src_y = 0; |
| 221 | 244 | |
| 222 | - } else {
|
|
| 245 | + } else { |
|
| 223 | 246 | $src_w = $src_width; |
| 224 | 247 | $src_h = $this->get_prop_height($src_width); |
| 225 | 248 | $src_x = 0; |
@@ -228,8 +251,9 @@ discard block |
||
| 228 | 251 | |
| 229 | 252 | return imagecopyresampled($this->image, $src, 0, 0, $src_x, $src_y, $this->width, $this->height, $src_w, $src_h); |
| 230 | 253 | |
| 231 | - } else |
|
| 232 | - return false; |
|
| 254 | + } else { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 233 | 257 | } |
| 234 | 258 | |
| 235 | 259 | /** Resize image to fit in given resolution. Returns TRUE on success or FALSE on failure |
@@ -237,15 +261,22 @@ discard block |
||
| 237 | 261 | * @param integer $height |
| 238 | 262 | * @return bool */ |
| 239 | 263 | |
| 240 | - public function resize_fit($width, $height) {
|
|
| 241 | - if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) |
|
| 242 | - return true; |
|
| 243 | - if (!$width || (($height / $width) < ($this->height / $this->width))) |
|
| 244 | - $width = intval(($this->width * $height) / $this->height); |
|
| 245 | - elseif (!$height || (($width / $height) < ($this->width / $this->height))) |
|
| 246 | - $height = intval(($this->height * $width) / $this->width); |
|
| 247 | - if (!$width) $width = 1; |
|
| 248 | - if (!$height) $height = 1; |
|
| 264 | + public function resize_fit($width, $height) |
|
| 265 | + { |
|
| 266 | + if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) { |
|
| 267 | + return true; |
|
| 268 | + } |
|
| 269 | + if (!$width || (($height / $width) < ($this->height / $this->width))) { |
|
| 270 | + $width = intval(($this->width * $height) / $this->height); |
|
| 271 | + } elseif (!$height || (($width / $height) < ($this->width / $this->height))) { |
|
| 272 | + $height = intval(($this->height * $width) / $this->width); |
|
| 273 | + } |
|
| 274 | + if (!$width) { |
|
| 275 | + $width = 1; |
|
| 276 | + } |
|
| 277 | + if (!$height) { |
|
| 278 | + $height = 1; |
|
| 279 | + } |
|
| 249 | 280 | return $this->resize($width, $height); |
| 250 | 281 | } |
| 251 | 282 | |
@@ -256,7 +287,8 @@ discard block |
||
| 256 | 287 | * @param integer $height |
| 257 | 288 | * @return bool */ |
| 258 | 289 | |
| 259 | - public function resize_overflow($width, $height) {
|
|
| 290 | + public function resize_overflow($width, $height) |
|
| 291 | + { |
|
| 260 | 292 | |
| 261 | 293 | $big = (($this->width / $this->height) > ($width / $height)) |
| 262 | 294 | ? ($this->width * $height) / $this->height |
@@ -265,7 +297,7 @@ discard block |
||
| 265 | 297 | |
| 266 | 298 | $return = ($img = new gd($this->image, $big)); |
| 267 | 299 | |
| 268 | - if ($return) {
|
|
| 300 | + if ($return) { |
|
| 269 | 301 | $this->image = $img->get_image(); |
| 270 | 302 | $this->width = $img->get_width(); |
| 271 | 303 | $this->height = $img->get_height(); |
@@ -274,7 +306,8 @@ discard block |
||
| 274 | 306 | return $return; |
| 275 | 307 | } |
| 276 | 308 | |
| 277 | - public function gd_color() {
|
|
| 309 | + public function gd_color() |
|
| 310 | + { |
|
| 278 | 311 | $args = func_get_args(); |
| 279 | 312 | |
| 280 | 313 | $expr_rgb = '/^rgb\(\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\)$/i';
|
@@ -282,22 +315,23 @@ discard block |
||
| 282 | 315 | $expr_hex2 = '/^\#?([0-9a-f])([0-9a-f])([0-9a-f])$/i'; |
| 283 | 316 | $expr_byte = '/^([01]?\d?\d|2[0-4]\d|25[0-5])$/'; |
| 284 | 317 | |
| 285 | - if (!isset($args[0])) |
|
| 286 | - return false; |
|
| 318 | + if (!isset($args[0])) { |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 287 | 321 | |
| 288 | - if (count($args[0]) == 3) {
|
|
| 322 | + if (count($args[0]) == 3) { |
|
| 289 | 323 | list($r, $g, $b) = $args[0]; |
| 290 | 324 | |
| 291 | - } elseif (preg_match($expr_rgb, $args[0])) {
|
|
| 325 | + } elseif (preg_match($expr_rgb, $args[0])) { |
|
| 292 | 326 | list($r, $g, $b) = explode(" ", preg_replace($expr_rgb, "$1 $2 $3", $args[0]));
|
| 293 | 327 | |
| 294 | - } elseif (preg_match($expr_hex1, $args[0])) {
|
|
| 328 | + } elseif (preg_match($expr_hex1, $args[0])) { |
|
| 295 | 329 | list($r, $g, $b) = explode(" ", preg_replace($expr_hex1, "$1 $2 $3", $args[0]));
|
| 296 | 330 | $r = hexdec($r); |
| 297 | 331 | $g = hexdec($g); |
| 298 | 332 | $b = hexdec($b); |
| 299 | 333 | |
| 300 | - } elseif (preg_match($expr_hex2, $args[0])) {
|
|
| 334 | + } elseif (preg_match($expr_hex2, $args[0])) { |
|
| 301 | 335 | list($r, $g, $b) = explode(" ", preg_replace($expr_hex2, "$1$1 $2$2 $3$3", $args[0]));
|
| 302 | 336 | $r = hexdec($r); |
| 303 | 337 | $g = hexdec($g); |
@@ -307,16 +341,18 @@ discard block |
||
| 307 | 341 | preg_match($expr_byte, $args[0]) && |
| 308 | 342 | preg_match($expr_byte, $args[1]) && |
| 309 | 343 | preg_match($expr_byte, $args[2]) |
| 310 | - ) {
|
|
| 344 | + ) { |
|
| 311 | 345 | list($r, $g, $b) = $args; |
| 312 | 346 | |
| 313 | - } else |
|
| 314 | - return false; |
|
| 347 | + } else { |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 315 | 350 | |
| 316 | 351 | return imagecolorallocate($this->image, $r, $g, $b); |
| 317 | 352 | } |
| 318 | 353 | |
| 319 | - public function fill_color($color) {
|
|
| 354 | + public function fill_color($color) |
|
| 355 | + { |
|
| 320 | 356 | return $this->imagefilledrectangle(0, 0, $this->width - 1, $this->height - 1, $color); |
| 321 | 357 | } |
| 322 | 358 | |
@@ -329,20 +365,29 @@ discard block |
||
| 329 | 365 | $src_x=0, $src_y=0, |
| 330 | 366 | $dst_w=null, $dst_h=null, |
| 331 | 367 | $src_w=null, $src_h=null |
| 332 | - ) {
|
|
| 368 | + ) { |
|
| 333 | 369 | $image_details = $this->build_image($src); |
| 334 | 370 | |
| 335 | - if ($image_details !== false) {
|
|
| 371 | + if ($image_details !== false) { |
|
| 336 | 372 | list($src, $src_width, $src_height) = $image_details; |
| 337 | 373 | |
| 338 | - if (is_null($dst_w)) $dst_w = $this->width - $dst_x; |
|
| 339 | - if (is_null($dst_h)) $dst_h = $this->height - $dst_y; |
|
| 340 | - if (is_null($src_w)) $src_w = $src_width - $src_x; |
|
| 341 | - if (is_null($src_h)) $src_h = $src_height - $src_y; |
|
| 374 | + if (is_null($dst_w)) { |
|
| 375 | + $dst_w = $this->width - $dst_x; |
|
| 376 | + } |
|
| 377 | + if (is_null($dst_h)) { |
|
| 378 | + $dst_h = $this->height - $dst_y; |
|
| 379 | + } |
|
| 380 | + if (is_null($src_w)) { |
|
| 381 | + $src_w = $src_width - $src_x; |
|
| 382 | + } |
|
| 383 | + if (is_null($src_h)) { |
|
| 384 | + $src_h = $src_height - $src_y; |
|
| 385 | + } |
|
| 342 | 386 | return imagecopy($this->image, $src, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); |
| 343 | 387 | |
| 344 | - } else |
|
| 345 | - return false; |
|
| 388 | + } else { |
|
| 389 | + return false; |
|
| 390 | + } |
|
| 346 | 391 | } |
| 347 | 392 | |
| 348 | 393 | public function imagecopyresampled( |
@@ -351,16 +396,24 @@ discard block |
||
| 351 | 396 | $src_x=0, $src_y=0, |
| 352 | 397 | $dst_w=null, $dst_h=null, |
| 353 | 398 | $src_w=null, $src_h=null |
| 354 | - ) {
|
|
| 399 | + ) { |
|
| 355 | 400 | $image_details = $this->build_image($src); |
| 356 | 401 | |
| 357 | - if ($image_details !== false) {
|
|
| 402 | + if ($image_details !== false) { |
|
| 358 | 403 | list($src, $src_width, $src_height) = $image_details; |
| 359 | 404 | |
| 360 | - if (is_null($dst_w)) $dst_w = $this->width - $dst_x; |
|
| 361 | - if (is_null($dst_h)) $dst_h = $this->height - $dst_y; |
|
| 362 | - if (is_null($src_w)) $src_w = $src_width - $src_x; |
|
| 363 | - if (is_null($src_h)) $src_h = $src_height - $src_y; |
|
| 405 | + if (is_null($dst_w)) { |
|
| 406 | + $dst_w = $this->width - $dst_x; |
|
| 407 | + } |
|
| 408 | + if (is_null($dst_h)) { |
|
| 409 | + $dst_h = $this->height - $dst_y; |
|
| 410 | + } |
|
| 411 | + if (is_null($src_w)) { |
|
| 412 | + $src_w = $src_width - $src_x; |
|
| 413 | + } |
|
| 414 | + if (is_null($src_h)) { |
|
| 415 | + $src_h = $src_height - $src_y; |
|
| 416 | + } |
|
| 364 | 417 | imagealphablending($this->image, false); |
| 365 | 418 | imagesavealpha($this->image,true); |
| 366 | 419 | |
@@ -371,7 +424,7 @@ discard block |
||
| 371 | 424 | |
| 372 | 425 | $transindex = imagecolortransparent($src); |
| 373 | 426 | $palletsize = imagecolorstotal($src); |
| 374 | - if($transindex >= 0 && $transindex < $palletsize) {
|
|
| 427 | + if($transindex >= 0 && $transindex < $palletsize) { |
|
| 375 | 428 | $transcol = imagecolorsforindex($src, $transindex); |
| 376 | 429 | |
| 377 | 430 | /*** end gif transparent fix ***/ |
@@ -380,44 +433,56 @@ discard block |
||
| 380 | 433 | imagefilledrectangle($this->image, 0, 0, $dst_w, $dst_h, $transindex); |
| 381 | 434 | imagecopyresampled($this->image, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
| 382 | 435 | imagecolortransparent($this->image, $transindex); |
| 383 | - for($y=0; $y<$dst_h; ++$y) |
|
| 384 | - for($x=0; $x<$dst_w; ++$x) |
|
| 385 | - if(((imagecolorat($this->image, $x, $y)>>24) & 0x7F) >= 100) imagesetpixel($this->image, $x, $y, $transindex); |
|
| 436 | + for($y=0; $y<$dst_h; ++$y) { |
|
| 437 | + for($x=0; |
|
| 438 | + } |
|
| 439 | + $x<$dst_w; ++$x) { |
|
| 440 | + if(((imagecolorat($this->image, $x, $y)>>24) & 0x7F) >= 100) imagesetpixel($this->image, $x, $y, $transindex); |
|
| 441 | + } |
|
| 386 | 442 | imagetruecolortopalette($this->image, true, 255); |
| 387 | - } |
|
| 388 | - else {
|
|
| 443 | + } else { |
|
| 389 | 444 | $transparent = imagecolorallocatealpha($this->image, 255, 255, 255, 127); |
| 390 | 445 | imagefilledrectangle($this->image, 0, 0, $dst_w, $dst_h, $transparent); |
| 391 | 446 | imagecopyresampled($this->image, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
| 392 | 447 | } |
| 393 | 448 | return $this->image; |
| 394 | 449 | |
| 395 | - } else |
|
| 396 | - return false; |
|
| 450 | + } else { |
|
| 451 | + return false; |
|
| 452 | + } |
|
| 397 | 453 | } |
| 398 | 454 | |
| 399 | - public function imagefilledrectangle($x1, $y1, $x2, $y2, $color) {
|
|
| 455 | + public function imagefilledrectangle($x1, $y1, $x2, $y2, $color) |
|
| 456 | + { |
|
| 400 | 457 | $color = $this->gd_color($color); |
| 401 | - if ($color === false) return false; |
|
| 458 | + if ($color === false) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 402 | 461 | return imagefilledrectangle($this->image, $x1, $y1, $x2, $y2, $color); |
| 403 | 462 | } |
| 404 | 463 | |
| 405 | - public function imagepng($filename=null, $quality=null, $filters=null) {
|
|
| 406 | - if (is_null($filename) && !headers_sent()) |
|
| 407 | - header("Content-Type: image/png");
|
|
| 464 | + public function imagepng($filename=null, $quality=null, $filters=null) |
|
| 465 | + { |
|
| 466 | + if (is_null($filename) && !headers_sent()) { |
|
| 467 | + header("Content-Type: image/png"); |
|
| 468 | + } |
|
| 408 | 469 | @imagesavealpha($this->image, true); |
| 409 | 470 | return imagepng($this->image, $filename, $quality, $filters); |
| 410 | 471 | } |
| 411 | 472 | |
| 412 | - public function imagejpeg($filename=null, $quality=75) {
|
|
| 413 | - if (is_null($filename) && !headers_sent()) |
|
| 414 | - header("Content-Type: image/jpeg");
|
|
| 473 | + public function imagejpeg($filename=null, $quality=75) |
|
| 474 | + { |
|
| 475 | + if (is_null($filename) && !headers_sent()) { |
|
| 476 | + header("Content-Type: image/jpeg"); |
|
| 477 | + } |
|
| 415 | 478 | return imagejpeg($this->image, $filename, $quality); |
| 416 | 479 | } |
| 417 | 480 | |
| 418 | - public function imagegif($filename=null) {
|
|
| 419 | - if (is_null($filename) && !headers_sent()) |
|
| 420 | - header("Content-Type: image/gif");
|
|
| 481 | + public function imagegif($filename=null) |
|
| 482 | + { |
|
| 483 | + if (is_null($filename) && !headers_sent()) { |
|
| 484 | + header("Content-Type: image/gif"); |
|
| 485 | + } |
|
| 421 | 486 | @imagesavealpha($this->image, true); |
| 422 | 487 | return imagegif($this->image, $filename); |
| 423 | 488 | } |
@@ -179,7 +179,6 @@ |
||
| 179 | 179 | |
| 180 | 180 | /** Resize and crop the image to fit in given resolution. Returns TRUE on |
| 181 | 181 | * success or FALSE on failure |
| 182 | - * @param mixed $src |
|
| 183 | 182 | * @param integer $offset |
| 184 | 183 | * @return bool */ |
| 185 | 184 | abstract public function resizeCrop($width, $height, $offset=false); |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -abstract class image { |
|
| 15 | +abstract class image |
|
| 16 | +{ |
|
| 16 | 17 | const DEFAULT_JPEG_QUALITY = 75; |
| 17 | 18 | |
| 18 | 19 | /** Image resource or object |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | * @param string $property |
| 42 | 43 | * @return mixed */ |
| 43 | 44 | |
| 44 | - final public function __get($property) { |
|
| 45 | + final public function __get($property) |
|
| 46 | + { |
|
| 45 | 47 | return property_exists($this, $property) ? $this->$property : null; |
| 46 | 48 | } |
| 47 | 49 | |
@@ -57,14 +59,16 @@ discard block |
||
| 57 | 59 | * @param mixed $image |
| 58 | 60 | * @param array $options */ |
| 59 | 61 | |
| 60 | - public function __construct($image, array $options=array()) { |
|
| 62 | + public function __construct($image, array $options=array()) |
|
| 63 | + { |
|
| 61 | 64 | $this->image = $this->width = $this->height = null; |
| 62 | 65 | $imageDetails = $this->buildImage($image); |
| 63 | 66 | |
| 64 | - if ($imageDetails !== false) |
|
| 65 | - list($this->image, $this->width, $this->height) = $imageDetails; |
|
| 66 | - else |
|
| 67 | - $this->initError = true; |
|
| 67 | + if ($imageDetails !== false) { |
|
| 68 | + list($this->image, $this->width, $this->height) = $imageDetails; |
|
| 69 | + } else { |
|
| 70 | + $this->initError = true; |
|
| 71 | + } |
|
| 68 | 72 | $this->options = $options; |
| 69 | 73 | } |
| 70 | 74 | |
@@ -75,7 +79,8 @@ discard block |
||
| 75 | 79 | * @param mixed $image |
| 76 | 80 | * @return object */ |
| 77 | 81 | |
| 78 | - final static function factory($driver, $image, array $options=array()) { |
|
| 82 | + final static function factory($driver, $image, array $options=array()) |
|
| 83 | + { |
|
| 79 | 84 | $class = "image_$driver"; |
| 80 | 85 | return new $class($image, $options); |
| 81 | 86 | } |
@@ -86,14 +91,18 @@ discard block |
||
| 86 | 91 | * @param array $drivers |
| 87 | 92 | * @return string */ |
| 88 | 93 | |
| 89 | - final static function getDriver(array $drivers=array('gd')) { |
|
| 94 | + final static function getDriver(array $drivers=array('gd')) |
|
| 95 | + { |
|
| 90 | 96 | foreach ($drivers as $driver) { |
| 91 | - if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) |
|
| 92 | - continue; |
|
| 97 | + if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) { |
|
| 98 | + continue; |
|
| 99 | + } |
|
| 93 | 100 | $class = "image_$driver"; |
| 94 | 101 | if (class_exists($class) && method_exists($class, "available")) { |
| 95 | 102 | eval("\$avail = $class::available();"); |
| 96 | - if ($avail) return $driver; |
|
| 103 | + if ($avail) { |
|
| 104 | + return $driver; |
|
| 105 | + } |
|
| 97 | 106 | } |
| 98 | 107 | } |
| 99 | 108 | return false; |
@@ -105,7 +114,8 @@ discard block |
||
| 105 | 114 | * @param mixed $image |
| 106 | 115 | * @return array */ |
| 107 | 116 | |
| 108 | - final protected function buildImage($image) { |
|
| 117 | + final protected function buildImage($image) |
|
| 118 | + { |
|
| 109 | 119 | $class = get_class($this); |
| 110 | 120 | if ($image instanceof $class) { |
| 111 | 121 | $width = $image->width; |
@@ -117,8 +127,9 @@ discard block |
||
| 117 | 127 | $height = $image[1]; |
| 118 | 128 | $img = $this->getBlankImage($width, $height); |
| 119 | 129 | |
| 120 | - } else |
|
| 121 | - $img = $this->getImage($image, $width, $height); |
|
| 130 | + } else { |
|
| 131 | + $img = $this->getImage($image, $width, $height); |
|
| 132 | + } |
|
| 122 | 133 | return ($img !== false) |
| 123 | 134 | ? array($img, $width, $height) |
| 124 | 135 | : false; |
@@ -129,9 +140,12 @@ discard block |
||
| 129 | 140 | * @param integer $resizedHeight |
| 130 | 141 | * @return integer */ |
| 131 | 142 | |
| 132 | - final public function getPropWidth($resizedHeight) { |
|
| 143 | + final public function getPropWidth($resizedHeight) |
|
| 144 | + { |
|
| 133 | 145 | $width = round(($this->width * $resizedHeight) / $this->height); |
| 134 | - if (!$width) $width = 1; |
|
| 146 | + if (!$width) { |
|
| 147 | + $width = 1; |
|
| 148 | + } |
|
| 135 | 149 | return $width; |
| 136 | 150 | } |
| 137 | 151 | |
@@ -140,9 +154,12 @@ discard block |
||
| 140 | 154 | * @param integer $resizedWidth |
| 141 | 155 | * @return integer */ |
| 142 | 156 | |
| 143 | - final public function getPropHeight($resizedWidth) { |
|
| 157 | + final public function getPropHeight($resizedWidth) |
|
| 158 | + { |
|
| 144 | 159 | $height = round(($this->height * $resizedWidth) / $this->width); |
| 145 | - if (!$height) $height = 1; |
|
| 160 | + if (!$height) { |
|
| 161 | + $height = 1; |
|
| 162 | + } |
|
| 146 | 163 | return $height; |
| 147 | 164 | } |
| 148 | 165 | |
@@ -151,13 +168,17 @@ discard block |
||
| 151 | 168 | * static method should be implemented into driver classes like abstract |
| 152 | 169 | * methods |
| 153 | 170 | * @return bool */ |
| 154 | - static function available() { return false; } |
|
| 171 | + static function available() |
|
| 172 | + { |
|
| 173 | +return false; } |
|
| 155 | 174 | |
| 156 | 175 | /** Checks if file is an image. This static method should be implemented into |
| 157 | 176 | * driver classes like abstract methods |
| 158 | 177 | * @param string $file |
| 159 | 178 | * @return bool */ |
| 160 | - static function checkImage($file) { return false; } |
|
| 179 | + static function checkImage($file) |
|
| 180 | + { |
|
| 181 | +return false; } |
|
| 161 | 182 | |
| 162 | 183 | /** Resize image. Should return TRUE on success or FALSE on failure |
| 163 | 184 | * @param integer $width |
@@ -327,6 +327,11 @@ |
||
| 327 | 327 | return imagecolorallocate($this->image, $r, $g, $b); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | + /** |
|
| 331 | + * @param integer $x1 |
|
| 332 | + * @param integer $y1 |
|
| 333 | + * @param boolean $color |
|
| 334 | + */ |
|
| 330 | 335 | protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color) { |
| 331 | 336 | $color = $this->gdColor($color); |
| 332 | 337 | if ($color === false) return false; |
@@ -12,14 +12,20 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class image_gd extends image { |
|
| 15 | +class image_gd extends image |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | |
| 18 | 19 | // ABSTRACT PUBLIC METHODS |
| 19 | 20 | |
| 20 | - public function resize($width, $height) { |
|
| 21 | - if (!$width) $width = 1; |
|
| 22 | - if (!$height) $height = 1; |
|
| 21 | + public function resize($width, $height) |
|
| 22 | + { |
|
| 23 | + if (!$width) { |
|
| 24 | + $width = 1; |
|
| 25 | + } |
|
| 26 | + if (!$height) { |
|
| 27 | + $height = 1; |
|
| 28 | + } |
|
| 23 | 29 | return ( |
| 24 | 30 | (false !== ($img = new image_gd(array($width, $height)))) && |
| 25 | 31 | $img->imageCopyResampled($this) && |
@@ -29,9 +35,11 @@ discard block |
||
| 29 | 35 | ); |
| 30 | 36 | } |
| 31 | 37 | |
| 32 | - public function resizeFit($width, $height, $background=false) { |
|
| 33 | - if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) |
|
| 34 | - return true; |
|
| 38 | + public function resizeFit($width, $height, $background=false) |
|
| 39 | + { |
|
| 40 | + if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) { |
|
| 41 | + return true; |
|
| 42 | + } |
|
| 35 | 43 | if (!$width || (($height / $width) < ($this->height / $this->width))) { |
| 36 | 44 | $h = $height; |
| 37 | 45 | $w = round(($this->width * $h) / $this->height); |
@@ -42,13 +50,16 @@ discard block |
||
| 42 | 50 | $w = $width; |
| 43 | 51 | $h = $height; |
| 44 | 52 | } |
| 45 | - if (!$w) $w = 1; |
|
| 46 | - if (!$h) $h = 1; |
|
| 47 | - |
|
| 48 | - if ($background === false) |
|
| 49 | - return $this->resize($w, $h); |
|
| 53 | + if (!$w) { |
|
| 54 | + $w = 1; |
|
| 55 | + } |
|
| 56 | + if (!$h) { |
|
| 57 | + $h = 1; |
|
| 58 | + } |
|
| 50 | 59 | |
| 51 | - else { |
|
| 60 | + if ($background === false) { |
|
| 61 | + return $this->resize($w, $h); |
|
| 62 | + } else { |
|
| 52 | 63 | $img = new image_gd(array($width, $height)); |
| 53 | 64 | $x = round(($width - $w) / 2); |
| 54 | 65 | $y = round(($height - $h) / 2); |
@@ -56,8 +67,9 @@ discard block |
||
| 56 | 67 | if ((false === $this->resize($w, $h)) || |
| 57 | 68 | (false === $img->imageFilledRectangle(0, 0, $width, $height, $background)) || |
| 58 | 69 | (false === $img->imageCopyResampled($this->image, $x, $y, 0, 0, $w, $h)) |
| 59 | - ) |
|
| 60 | - return false; |
|
| 70 | + ) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 61 | 73 | |
| 62 | 74 | $this->image = $img->image; |
| 63 | 75 | $this->width = $width; |
@@ -67,41 +79,52 @@ discard block |
||
| 67 | 79 | } |
| 68 | 80 | } |
| 69 | 81 | |
| 70 | - public function resizeCrop($width, $height, $offset=false) { |
|
| 82 | + public function resizeCrop($width, $height, $offset=false) |
|
| 83 | + { |
|
| 71 | 84 | |
| 72 | 85 | if (($this->width / $this->height) > ($width / $height)) { |
| 73 | 86 | $h = $height; |
| 74 | 87 | $w = ($this->width * $h) / $this->height; |
| 75 | 88 | $y = 0; |
| 76 | 89 | if ($offset !== false) { |
| 77 | - if ($offset > 0) |
|
| 78 | - $offset = -$offset; |
|
| 79 | - if (($w + $offset) <= $width) |
|
| 80 | - $offset = $width - $w; |
|
| 90 | + if ($offset > 0) { |
|
| 91 | + $offset = -$offset; |
|
| 92 | + } |
|
| 93 | + if (($w + $offset) <= $width) { |
|
| 94 | + $offset = $width - $w; |
|
| 95 | + } |
|
| 81 | 96 | $x = $offset; |
| 82 | - } else |
|
| 83 | - $x = ($width - $w) / 2; |
|
| 97 | + } else { |
|
| 98 | + $x = ($width - $w) / 2; |
|
| 99 | + } |
|
| 84 | 100 | |
| 85 | 101 | } else { |
| 86 | 102 | $w = $width; |
| 87 | 103 | $h = ($this->height * $w) / $this->width; |
| 88 | 104 | $x = 0; |
| 89 | 105 | if ($offset !== false) { |
| 90 | - if ($offset > 0) |
|
| 91 | - $offset = -$offset; |
|
| 92 | - if (($h + $offset) <= $height) |
|
| 93 | - $offset = $height - $h; |
|
| 106 | + if ($offset > 0) { |
|
| 107 | + $offset = -$offset; |
|
| 108 | + } |
|
| 109 | + if (($h + $offset) <= $height) { |
|
| 110 | + $offset = $height - $h; |
|
| 111 | + } |
|
| 94 | 112 | $y = $offset; |
| 95 | - } else |
|
| 96 | - $y = ($height - $h) / 2; |
|
| 113 | + } else { |
|
| 114 | + $y = ($height - $h) / 2; |
|
| 115 | + } |
|
| 97 | 116 | } |
| 98 | 117 | |
| 99 | 118 | $x = round($x); |
| 100 | 119 | $y = round($y); |
| 101 | 120 | $w = round($w); |
| 102 | 121 | $h = round($h); |
| 103 | - if (!$w) $w = 1; |
|
| 104 | - if (!$h) $h = 1; |
|
| 122 | + if (!$w) { |
|
| 123 | + $w = 1; |
|
| 124 | + } |
|
| 125 | + if (!$h) { |
|
| 126 | + $h = 1; |
|
| 127 | + } |
|
| 105 | 128 | |
| 106 | 129 | $return = ( |
| 107 | 130 | (false !== ($img = new image_gd(array($width, $height))))) && |
@@ -117,50 +140,59 @@ discard block |
||
| 117 | 140 | return $return; |
| 118 | 141 | } |
| 119 | 142 | |
| 120 | - public function rotate($angle, $background="#000000") { |
|
| 143 | + public function rotate($angle, $background="#000000") |
|
| 144 | + { |
|
| 121 | 145 | $angle = -$angle; |
| 122 | 146 | $img = @imagerotate($this->image, $angle, $this->gdColor($background)); |
| 123 | - if ($img === false) |
|
| 124 | - return false; |
|
| 147 | + if ($img === false) { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 125 | 150 | $this->width = imagesx($img); |
| 126 | 151 | $this->height = imagesy($img); |
| 127 | 152 | $this->image = $img; |
| 128 | 153 | return true; |
| 129 | 154 | } |
| 130 | 155 | |
| 131 | - public function flipHorizontal() { |
|
| 156 | + public function flipHorizontal() |
|
| 157 | + { |
|
| 132 | 158 | $img = imagecreatetruecolor($this->width, $this->height); |
| 133 | 159 | imagealphablending($img, false); |
| 134 | 160 | imagesavealpha($img, true); |
| 135 | - if (imagecopyresampled($img, $this->image, 0, 0, ($this->width - 1), 0, $this->width, $this->height, -$this->width, $this->height)) |
|
| 136 | - $this->image = $img; |
|
| 137 | - else |
|
| 138 | - return false; |
|
| 161 | + if (imagecopyresampled($img, $this->image, 0, 0, ($this->width - 1), 0, $this->width, $this->height, -$this->width, $this->height)) { |
|
| 162 | + $this->image = $img; |
|
| 163 | + } else { |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 139 | 166 | return true; |
| 140 | 167 | } |
| 141 | 168 | |
| 142 | - public function flipVertical() { |
|
| 169 | + public function flipVertical() |
|
| 170 | + { |
|
| 143 | 171 | $img = imagecreatetruecolor($this->width, $this->height); |
| 144 | 172 | imagealphablending($img, false); |
| 145 | 173 | imagesavealpha($img, true); |
| 146 | - if (imagecopyresampled($img, $this->image, 0, 0, 0, ($this->height - 1), $this->width, $this->height, $this->width, -$this->height)) |
|
| 147 | - $this->image = $img; |
|
| 148 | - else |
|
| 149 | - return false; |
|
| 174 | + if (imagecopyresampled($img, $this->image, 0, 0, 0, ($this->height - 1), $this->width, $this->height, $this->width, -$this->height)) { |
|
| 175 | + $this->image = $img; |
|
| 176 | + } else { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 150 | 179 | return true; |
| 151 | 180 | } |
| 152 | 181 | |
| 153 | - public function watermark($file, $left=false, $top=false) { |
|
| 182 | + public function watermark($file, $left=false, $top=false) |
|
| 183 | + { |
|
| 154 | 184 | $info = getimagesize($file); |
| 155 | 185 | list($w, $h, $t) = $info; |
| 156 | - if (!in_array($t, array(IMAGETYPE_PNG, IMAGETYPE_GIF))) |
|
| 157 | - return false; |
|
| 186 | + if (!in_array($t, array(IMAGETYPE_PNG, IMAGETYPE_GIF))) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 158 | 189 | $imagecreate = ($t == IMAGETYPE_PNG) ? "imagecreatefrompng" : "imagecreatefromgif"; |
| 159 | 190 | |
| 160 | 191 | if (!@imagealphablending($this->image, true) || |
| 161 | 192 | (false === ($wm = @$imagecreate($file))) |
| 162 | - ) |
|
| 163 | - return false; |
|
| 193 | + ) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 164 | 196 | |
| 165 | 197 | $w = imagesx($wm); |
| 166 | 198 | $h = imagesy($wm); |
@@ -176,28 +208,33 @@ discard block |
||
| 176 | 208 | if ((($x + $w) > $this->width) || |
| 177 | 209 | (($y + $h) > $this->height) || |
| 178 | 210 | ($x < 0) || ($y < 0) |
| 179 | - ) |
|
| 180 | - return false; |
|
| 211 | + ) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 181 | 214 | |
| 182 | - if (($wm === false) || !@imagecopy($this->image, $wm, $x, $y, 0, 0, $w, $h)) |
|
| 183 | - return false; |
|
| 215 | + if (($wm === false) || !@imagecopy($this->image, $wm, $x, $y, 0, 0, $w, $h)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 184 | 218 | |
| 185 | 219 | @imagealphablending($this->image, false); |
| 186 | 220 | @imagesavealpha($this->image, true); |
| 187 | 221 | return true; |
| 188 | 222 | } |
| 189 | 223 | |
| 190 | - public function output($type='jpeg', array $options=array()) { |
|
| 224 | + public function output($type='jpeg', array $options=array()) |
|
| 225 | + { |
|
| 191 | 226 | $method = "output_$type"; |
| 192 | - if (!method_exists($this, $method)) |
|
| 193 | - return false; |
|
| 227 | + if (!method_exists($this, $method)) { |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 194 | 230 | return $this->$method($options); |
| 195 | 231 | } |
| 196 | 232 | |
| 197 | 233 | |
| 198 | 234 | // ABSTRACT PROTECTED METHODS |
| 199 | 235 | |
| 200 | - protected function getBlankImage($width, $height) { |
|
| 236 | + protected function getBlankImage($width, $height) |
|
| 237 | + { |
|
| 201 | 238 | $img = @imagecreatetruecolor($width, $height); |
| 202 | 239 | // imagealphablending($img, false); |
| 203 | 240 | // imagesavealpha($img, true); |
@@ -207,7 +244,8 @@ discard block |
||
| 207 | 244 | return $img; |
| 208 | 245 | } |
| 209 | 246 | |
| 210 | - protected function getImage($image, &$width, &$height) { |
|
| 247 | + protected function getImage($image, &$width, &$height) |
|
| 248 | + { |
|
| 211 | 249 | |
| 212 | 250 | if (is_resource($image) && (get_resource_type($image) == "gd")) { |
| 213 | 251 | $width = @imagesx($image); |
@@ -227,22 +265,26 @@ discard block |
||
| 227 | 265 | |
| 228 | 266 | return $image; |
| 229 | 267 | |
| 230 | - } else |
|
| 231 | - return false; |
|
| 268 | + } else { |
|
| 269 | + return false; |
|
| 270 | + } |
|
| 232 | 271 | } |
| 233 | 272 | |
| 234 | 273 | |
| 235 | 274 | // PSEUDO-ABSTRACT STATIC METHODS |
| 236 | 275 | |
| 237 | - static function available() { |
|
| 276 | + static function available() |
|
| 277 | + { |
|
| 238 | 278 | return function_exists("imagecreatefromjpeg"); |
| 239 | 279 | } |
| 240 | 280 | |
| 241 | - static function checkImage($file) { |
|
| 281 | + static function checkImage($file) |
|
| 282 | + { |
|
| 242 | 283 | if (!is_string($file) || |
| 243 | 284 | ((false === (list($width, $height, $t) = @getimagesize($file)))) |
| 244 | - ) |
|
| 245 | - return false; |
|
| 285 | + ) { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 246 | 288 | |
| 247 | 289 | $img = |
| 248 | 290 | ($t == IMAGETYPE_GIF) ? @imagecreatefromgif($file) : ( |
@@ -258,34 +300,41 @@ discard block |
||
| 258 | 300 | |
| 259 | 301 | // OWN METHODS |
| 260 | 302 | |
| 261 | - protected function output_png(array $options=array()) { |
|
| 303 | + protected function output_png(array $options=array()) |
|
| 304 | + { |
|
| 262 | 305 | $file = isset($options['file']) ? $options['file'] : null; |
| 263 | 306 | $quality = isset($options['quality']) ? $options['quality'] : null; |
| 264 | 307 | $filters = isset($options['filters']) ? $options['filters'] : null; |
| 265 | - if (($file === null) && !headers_sent()) |
|
| 266 | - header("Content-Type: image/png"); |
|
| 308 | + if (($file === null) && !headers_sent()) { |
|
| 309 | + header("Content-Type: image/png"); |
|
| 310 | + } |
|
| 267 | 311 | @imagesavealpha($this->image, true); |
| 268 | 312 | return imagepng($this->image, $file, $quality, $filters); |
| 269 | 313 | } |
| 270 | 314 | |
| 271 | - protected function output_jpeg(array $options=array()) { |
|
| 315 | + protected function output_jpeg(array $options=array()) |
|
| 316 | + { |
|
| 272 | 317 | $file = isset($options['file']) ? $options['file'] : null; |
| 273 | 318 | $quality = isset($options['quality']) |
| 274 | 319 | ? $options['quality'] |
| 275 | 320 | : self::DEFAULT_JPEG_QUALITY; |
| 276 | - if (($file === null) && !headers_sent()) |
|
| 277 | - header("Content-Type: image/jpeg"); |
|
| 321 | + if (($file === null) && !headers_sent()) { |
|
| 322 | + header("Content-Type: image/jpeg"); |
|
| 323 | + } |
|
| 278 | 324 | return imagejpeg($this->image, $file, $quality); |
| 279 | 325 | } |
| 280 | 326 | |
| 281 | - protected function output_gif(array $options=array()) { |
|
| 327 | + protected function output_gif(array $options=array()) |
|
| 328 | + { |
|
| 282 | 329 | $file = isset($options['file']) ? $options['file'] : null; |
| 283 | - if (isset($options['file']) && !headers_sent()) |
|
| 284 | - header("Content-Type: image/gif"); |
|
| 330 | + if (isset($options['file']) && !headers_sent()) { |
|
| 331 | + header("Content-Type: image/gif"); |
|
| 332 | + } |
|
| 285 | 333 | return imagegif($this->image, $file); |
| 286 | 334 | } |
| 287 | 335 | |
| 288 | - protected function gdColor() { |
|
| 336 | + protected function gdColor() |
|
| 337 | + { |
|
| 289 | 338 | $args = func_get_args(); |
| 290 | 339 | |
| 291 | 340 | $exprRGB = '/^rgb\(\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\)$/i'; |
@@ -293,8 +342,9 @@ discard block |
||
| 293 | 342 | $exprHex2 = '/^\#?([0-9a-f])([0-9a-f])([0-9a-f])$/i'; |
| 294 | 343 | $exprByte = '/^([01]?\d?\d|2[0-4]\d|25[0-5])$/'; |
| 295 | 344 | |
| 296 | - if (!isset($args[0])) |
|
| 297 | - return false; |
|
| 345 | + if (!isset($args[0])) { |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 298 | 348 | |
| 299 | 349 | if (count($args[0]) == 3) { |
| 300 | 350 | list($r, $g, $b) = $args[0]; |
@@ -321,15 +371,19 @@ discard block |
||
| 321 | 371 | ) { |
| 322 | 372 | list($r, $g, $b) = $args; |
| 323 | 373 | |
| 324 | - } else |
|
| 325 | - return false; |
|
| 374 | + } else { |
|
| 375 | + return false; |
|
| 376 | + } |
|
| 326 | 377 | |
| 327 | 378 | return imagecolorallocate($this->image, $r, $g, $b); |
| 328 | 379 | } |
| 329 | 380 | |
| 330 | - protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color) { |
|
| 381 | + protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color) |
|
| 382 | + { |
|
| 331 | 383 | $color = $this->gdColor($color); |
| 332 | - if ($color === false) return false; |
|
| 384 | + if ($color === false) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 333 | 387 | return imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color); |
| 334 | 388 | } |
| 335 | 389 | |
@@ -338,15 +392,24 @@ discard block |
||
| 338 | 392 | ) { |
| 339 | 393 | $imageDetails = $this->buildImage($src); |
| 340 | 394 | |
| 341 | - if ($imageDetails === false) |
|
| 342 | - return false; |
|
| 395 | + if ($imageDetails === false) { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 343 | 398 | |
| 344 | 399 | list($src, $srcWidth, $srcHeight) = $imageDetails; |
| 345 | 400 | |
| 346 | - if (is_null($dstW)) $dstW = $this->width - $dstW; |
|
| 347 | - if (is_null($dstH)) $dstH = $this->height - $dstY; |
|
| 348 | - if (is_null($srcW)) $srcW = $srcWidth - $srcX; |
|
| 349 | - if (is_null($srcH)) $srcH = $srcHeight - $srcY; |
|
| 401 | + if (is_null($dstW)) { |
|
| 402 | + $dstW = $this->width - $dstW; |
|
| 403 | + } |
|
| 404 | + if (is_null($dstH)) { |
|
| 405 | + $dstH = $this->height - $dstY; |
|
| 406 | + } |
|
| 407 | + if (is_null($srcW)) { |
|
| 408 | + $srcW = $srcWidth - $srcX; |
|
| 409 | + } |
|
| 410 | + if (is_null($srcH)) { |
|
| 411 | + $srcH = $srcHeight - $srcY; |
|
| 412 | + } |
|
| 350 | 413 | return imageCopyResampled($this->image, $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); |
| 351 | 414 | } |
| 352 | 415 | } |
@@ -18,6 +18,9 @@ discard block |
||
| 18 | 18 | protected $root; |
| 19 | 19 | protected $ignored; |
| 20 | 20 | |
| 21 | + /** |
|
| 22 | + * @param string $folder |
|
| 23 | + */ |
|
| 21 | 24 | function __construct($file, $folder, $ignored=null) { |
| 22 | 25 | $this->zip = new ZipArchive(); |
| 23 | 26 | |
@@ -39,6 +42,9 @@ discard block |
||
| 39 | 42 | $this->zip->close(); |
| 40 | 43 | } |
| 41 | 44 | |
| 45 | + /** |
|
| 46 | + * @param string $folder |
|
| 47 | + */ |
|
| 42 | 48 | function zip($folder, $parent=null) { |
| 43 | 49 | $full_path = "{$this->root}$parent$folder"; |
| 44 | 50 | $zip_path = "$parent$folder"; |
@@ -13,20 +13,23 @@ discard block |
||
| 13 | 13 | * @link http://kcfinder.sunhater.com |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -class zipFolder { |
|
| 16 | +class zipFolder |
|
| 17 | +{ |
|
| 17 | 18 | protected $zip; |
| 18 | 19 | protected $root; |
| 19 | 20 | protected $ignored; |
| 20 | 21 | |
| 21 | - function __construct($file, $folder, $ignored=null) { |
|
| 22 | + function __construct($file, $folder, $ignored=null) |
|
| 23 | + { |
|
| 22 | 24 | $this->zip = new ZipArchive(); |
| 23 | 25 | |
| 24 | 26 | $this->ignored = is_array($ignored) |
| 25 | 27 | ? $ignored |
| 26 | 28 | : ($ignored ? array($ignored) : array()); |
| 27 | 29 | |
| 28 | - if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) |
|
| 29 | - throw new Exception("cannot open <$file>\n"); |
|
| 30 | + if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) { |
|
| 31 | + throw new Exception("cannot open <$file>\n"); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $folder = rtrim($folder, '/'); |
| 32 | 35 | |
@@ -39,19 +42,22 @@ discard block |
||
| 39 | 42 | $this->zip->close(); |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | - function zip($folder, $parent=null) { |
|
| 45 | + function zip($folder, $parent=null) |
|
| 46 | + { |
|
| 43 | 47 | $full_path = "{$this->root}$parent$folder"; |
| 44 | 48 | $zip_path = "$parent$folder"; |
| 45 | 49 | $this->zip->addEmptyDir($zip_path); |
| 46 | 50 | $dir = new DirectoryIterator($full_path); |
| 47 | - foreach ($dir as $file) |
|
| 48 | - if (!$file->isDot()) { |
|
| 51 | + foreach ($dir as $file) { |
|
| 52 | + if (!$file->isDot()) { |
|
| 49 | 53 | $filename = $file->getFilename(); |
| 54 | + } |
|
| 50 | 55 | if (!in_array($filename, $this->ignored)) { |
| 51 | - if ($file->isDir()) |
|
| 52 | - $this->zip($filename, "$zip_path/"); |
|
| 53 | - else |
|
| 54 | - $this->zip->addFile("$full_path/$filename", "$zip_path/$filename"); |
|
| 56 | + if ($file->isDir()) { |
|
| 57 | + $this->zip($filename, "$zip_path/"); |
|
| 58 | + } else { |
|
| 59 | + $this->zip->addFile("$full_path/$filename", "$zip_path/$filename"); |
|
| 60 | + } |
|
| 55 | 61 | } |
| 56 | 62 | } |
| 57 | 63 | } |
@@ -102,7 +102,6 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /** Checks if the given file is really writable. The standard PHP function |
| 104 | 104 | * is_writable() does not work properly on Windows servers. |
| 105 | - * @param string $dir |
|
| 106 | 105 | * @return bool */ |
| 107 | 106 | |
| 108 | 107 | static function isWritable($filename) { |
@@ -114,7 +113,6 @@ discard block |
||
| 114 | 113 | } |
| 115 | 114 | |
| 116 | 115 | /** Get the extension from filename |
| 117 | - * @param string $file |
|
| 118 | 116 | * @param bool $toLower |
| 119 | 117 | * @return string */ |
| 120 | 118 | |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class file { |
|
| 15 | +class file |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | static $MIME = array( |
| 18 | 19 | 'ai' => 'application/postscript', |
@@ -105,10 +106,12 @@ discard block |
||
| 105 | 106 | * @param string $dir |
| 106 | 107 | * @return bool */ |
| 107 | 108 | |
| 108 | - static function isWritable($filename) { |
|
| 109 | + static function isWritable($filename) |
|
| 110 | + { |
|
| 109 | 111 | $filename = path::normalize($filename); |
| 110 | - if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) |
|
| 111 | - return false; |
|
| 112 | + if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 112 | 115 | fclose($fp); |
| 113 | 116 | return true; |
| 114 | 117 | } |
@@ -118,7 +121,8 @@ discard block |
||
| 118 | 121 | * @param bool $toLower |
| 119 | 122 | * @return string */ |
| 120 | 123 | |
| 121 | - static function getExtension($filename, $toLower=true) { |
|
| 124 | + static function getExtension($filename, $toLower=true) |
|
| 125 | + { |
|
| 122 | 126 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
| 123 | 127 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
| 124 | 128 | } |
@@ -134,7 +138,8 @@ discard block |
||
| 134 | 138 | * @param string $magic |
| 135 | 139 | * @return string */ |
| 136 | 140 | |
| 137 | - static function getMimeType($filename, $magic=null) { |
|
| 141 | + static function getMimeType($filename, $magic=null) |
|
| 142 | + { |
|
| 138 | 143 | if (class_exists("finfo")) { |
| 139 | 144 | $finfo = ($magic === null) |
| 140 | 145 | ? new finfo(FILEINFO_MIME) |
@@ -170,12 +175,15 @@ discard block |
||
| 170 | 175 | * @param string $tpl |
| 171 | 176 | * @return string */ |
| 172 | 177 | |
| 173 | - static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
|
| 174 | - if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
|
| 178 | + static function getInexistantFilename($filename, $dir=null, $tpl=null) |
|
| 179 | + { |
|
| 180 | + if ($tpl === null) { |
|
| 181 | + $tpl = "{name}({sufix}){ext}"; |
|
| 182 | + } |
|
| 175 | 183 | $fullPath = ($dir === null); |
| 176 | - if ($fullPath) |
|
| 177 | - $dir = path::normalize(dirname($filename)); |
|
| 178 | - else { |
|
| 184 | + if ($fullPath) { |
|
| 185 | + $dir = path::normalize(dirname($filename)); |
|
| 186 | + } else { |
|
| 179 | 187 | $fdir = dirname($filename); |
| 180 | 188 | $dir = strlen($fdir) |
| 181 | 189 | ? path::normalize("$dir/$fdir") |
@@ -187,8 +195,9 @@ discard block |
||
| 187 | 195 | $tpl = str_replace('{name}', $name, $tpl); |
| 188 | 196 | $tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl); |
| 189 | 197 | $i = 1; $file = "$dir/$filename"; |
| 190 | - while (file_exists($file)) |
|
| 191 | - $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 198 | + while (file_exists($file)) { |
|
| 199 | + $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 200 | + } |
|
| 192 | 201 | |
| 193 | 202 | return $fullPath |
| 194 | 203 | ? $file |
@@ -12,17 +12,20 @@ |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class type_img { |
|
| 15 | +class type_img |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | - public function checkFile($file, array $config) { |
|
| 18 | + public function checkFile($file, array $config) |
|
| 19 | + { |
|
| 18 | 20 | |
| 19 | 21 | $driver = isset($config['imageDriversPriority']) |
| 20 | 22 | ? image::getDriver(explode(" ", $config['imageDriversPriority'])) : "gd"; |
| 21 | 23 | |
| 22 | 24 | $img = image::factory($driver, $file); |
| 23 | 25 | |
| 24 | - if ($img->initError) |
|
| 25 | - return "Unknown image format/encoding."; |
|
| 26 | + if ($img->initError) { |
|
| 27 | + return "Unknown image format/encoding."; |
|
| 28 | + } |
|
| 26 | 29 | |
| 27 | 30 | return true; |
| 28 | 31 | } |
@@ -12,20 +12,25 @@ |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class type_mime { |
|
| 15 | +class type_mime |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | - public function checkFile($file, array $config) { |
|
| 18 | - if (!class_exists("finfo")) |
|
| 19 | - return "Fileinfo PECL extension is missing."; |
|
| 18 | + public function checkFile($file, array $config) |
|
| 19 | + { |
|
| 20 | + if (!class_exists("finfo")) { |
|
| 21 | + return "Fileinfo PECL extension is missing."; |
|
| 22 | + } |
|
| 20 | 23 | |
| 21 | - if (!isset($config['params'])) |
|
| 22 | - return "Undefined MIME types."; |
|
| 24 | + if (!isset($config['params'])) { |
|
| 25 | + return "Undefined MIME types."; |
|
| 26 | + } |
|
| 23 | 27 | |
| 24 | 28 | $finfo = strlen($config['mime_magic']) |
| 25 | 29 | ? new finfo(FILEINFO_MIME, $config['mime_magic']) |
| 26 | 30 | : new finfo(FILEINFO_MIME); |
| 27 | - if (!$finfo) |
|
| 28 | - return "Opening fileinfo database failed."; |
|
| 31 | + if (!$finfo) { |
|
| 32 | + return "Opening fileinfo database failed."; |
|
| 33 | + } |
|
| 29 | 34 | |
| 30 | 35 | $type = $finfo->file($file); |
| 31 | 36 | $type = substr($type, 0, strrpos($type, ";")); |
@@ -14,7 +14,9 @@ |
||
| 14 | 14 | |
| 15 | 15 | require "core/autoload.php"; |
| 16 | 16 | $mtime = @filemtime(__FILE__); |
| 17 | -if ($mtime) httpCache::checkMTime($mtime); |
|
| 17 | +if ($mtime) { |
|
| 18 | + httpCache::checkMTime($mtime); |
|
| 19 | +} |
|
| 18 | 20 | $browser = new browser($modx); |
| 19 | 21 | $config = $browser->config; |
| 20 | 22 | ob_start(); |
@@ -10,11 +10,17 @@ |
||
| 10 | 10 | } |
| 11 | 11 | }; |
| 12 | 12 | <?php |
| 13 | - if(isset($_GET['type'])) $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
| 14 | - elseif(isset($_GET['Type'])) $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
| 15 | - else $type = 'images'; |
|
| 13 | + if(isset($_GET['type'])) { |
|
| 14 | + $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
| 15 | + } elseif(isset($_GET['Type'])) { |
|
| 16 | + $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
| 17 | + } else { |
|
| 18 | + $type = 'images'; |
|
| 19 | + } |
|
| 16 | 20 | |
| 17 | - if($type==='image') $type = 'images'; |
|
| 21 | + if($type==='image') { |
|
| 22 | + $type = 'images'; |
|
| 23 | + } |
|
| 18 | 24 | |
| 19 | 25 | $opener = (isset($_GET['editor'])) ? 'opener=' . htmlspecialchars(trim($_GET['editor']), ENT_QUOTES) : ''; |
| 20 | 26 | $request_uri = "{$opener}&type={$type}";
|