@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | namespace Bulletproof; |
| 11 | 11 | |
| 12 | - function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
|
|
| 12 | + function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight) {
|
|
| 13 | 13 | |
| 14 | 14 | switch ($mimeType) {
|
| 15 | 15 | case "jpg": |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | // Can't crop to a bigger size, ex: |
| 38 | 38 | // an image with 100X100 can not be cropped to 200X200. Image can only be cropped to smaller size. |
| 39 | 39 | if ($widthTrim < 0 && $heightTrim < 0) {
|
| 40 | - return ; |
|
| 40 | + return; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $temp = imagecreatetruecolor($newWidth, $newHeight); |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | namespace Bulletproof; |
| 11 | 11 | |
| 12 | - function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
|
|
| 12 | + function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight) { |
|
| 13 | 13 | |
| 14 | 14 | switch ($mimeType) {
|
| 15 | 15 | case "jpg": |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | namespace Bulletproof; |
| 11 | 11 | |
| 12 | -function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){
|
|
| 12 | +function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE) {
|
|
| 13 | 13 | |
| 14 | 14 | // First, calculate the height. |
| 15 | 15 | $height = intval($newWidth / $imgWidth * $imgHeight); |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | namespace Bulletproof; |
| 11 | 11 | |
| 12 | -function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){
|
|
| 12 | +function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE) { |
|
| 13 | 13 | |
| 14 | 14 | // First, calculate the height. |
| 15 | 15 | $height = intval($newWidth / $imgWidth * $imgHeight); |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | namespace Bulletproof; |
| 11 | 11 | |
| 12 | - function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
|
|
| 12 | + function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") {
|
|
| 13 | 13 | |
| 14 | 14 | // Calculate the watermark position |
| 15 | 15 | switch ($position) {
|
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | namespace Bulletproof; |
| 11 | 11 | |
| 12 | - function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
|
|
| 12 | + function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") { |
|
| 13 | 13 | |
| 14 | 14 | // Calculate the watermark position |
| 15 | 15 | switch ($position) {
|
@@ -110,8 +110,7 @@ discard block |
||
| 110 | 110 | /** |
| 111 | 111 | * @param array $_files represents the $_FILES array passed as dependancy |
| 112 | 112 | */ |
| 113 | - public function __construct(array $_files = []) |
|
| 114 | - {
|
|
| 113 | + public function __construct(array $_files = []) { |
|
| 115 | 114 | $this->_files = $_files; |
| 116 | 115 | } |
| 117 | 116 | |
@@ -122,8 +121,7 @@ discard block |
||
| 122 | 121 | * |
| 123 | 122 | * @return bool|string |
| 124 | 123 | */ |
| 125 | - protected function getImageMime($tmp_name) |
|
| 126 | - {
|
|
| 124 | + protected function getImageMime($tmp_name) { |
|
| 127 | 125 | if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
|
| 128 | 126 | return $this->imageMimes [exif_imagetype($tmp_name)]; |
| 129 | 127 | } |
@@ -145,8 +143,7 @@ discard block |
||
| 145 | 143 | * |
| 146 | 144 | * @return bool|mixed |
| 147 | 145 | */ |
| 148 | - public function offsetGet($offset) |
|
| 149 | - {
|
|
| 146 | + public function offsetGet($offset) { |
|
| 150 | 147 | if ($offset == "error") {
|
| 151 | 148 | return $this->error; |
| 152 | 149 | } |
@@ -166,8 +163,7 @@ discard block |
||
| 166 | 163 | * |
| 167 | 164 | * @return $this |
| 168 | 165 | */ |
| 169 | - public function setName($isNameProvided = null) |
|
| 170 | - {
|
|
| 166 | + public function setName($isNameProvided = null) { |
|
| 171 | 167 | if ($isNameProvided) {
|
| 172 | 168 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
| 173 | 169 | } |
@@ -182,8 +178,7 @@ discard block |
||
| 182 | 178 | * |
| 183 | 179 | * @return $this |
| 184 | 180 | */ |
| 185 | - public function setMime(array $fileTypes) |
|
| 186 | - {
|
|
| 181 | + public function setMime(array $fileTypes) { |
|
| 187 | 182 | $this->mimeTypes = $fileTypes; |
| 188 | 183 | return $this; |
| 189 | 184 | } |
@@ -196,8 +191,7 @@ discard block |
||
| 196 | 191 | * |
| 197 | 192 | * @return $this |
| 198 | 193 | */ |
| 199 | - public function setSize($min, $max) |
|
| 200 | - {
|
|
| 194 | + public function setSize($min, $max) { |
|
| 201 | 195 | $this->size = array($min, $max); |
| 202 | 196 | return $this; |
| 203 | 197 | } |
@@ -210,8 +204,7 @@ discard block |
||
| 210 | 204 | * |
| 211 | 205 | * @return $this |
| 212 | 206 | */ |
| 213 | - public function setLocation($dir = "bulletproof", $permission = 0666) |
|
| 214 | - {
|
|
| 207 | + public function setLocation($dir = "bulletproof", $permission = 0666) { |
|
| 215 | 208 | if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
|
| 216 | 209 | $createFolder = @mkdir("" . $dir, (int) $permission, true);
|
| 217 | 210 | if (!$createFolder) {
|
@@ -232,8 +225,7 @@ discard block |
||
| 232 | 225 | * |
| 233 | 226 | * @return $this |
| 234 | 227 | */ |
| 235 | - public function setDimension($maxWidth, $maxHeight) |
|
| 236 | - {
|
|
| 228 | + public function setDimension($maxWidth, $maxHeight) { |
|
| 237 | 229 | $this->dimensions = array($maxWidth, $maxHeight); |
| 238 | 230 | return $this; |
| 239 | 231 | } |
@@ -245,8 +237,7 @@ discard block |
||
| 245 | 237 | * |
| 246 | 238 | * @return $this |
| 247 | 239 | */ |
| 248 | - public function setErrorMessages($new_error_messages) |
|
| 249 | - {
|
|
| 240 | + public function setErrorMessages($new_error_messages) { |
|
| 250 | 241 | if($new_array = array_replace_recursive($this->error_messages, $new_error_messages)) {
|
| 251 | 242 | $this->error_messages = $new_array; |
| 252 | 243 | }; |
@@ -258,8 +249,7 @@ discard block |
||
| 258 | 249 | * |
| 259 | 250 | * @return string |
| 260 | 251 | */ |
| 261 | - public function getName() |
|
| 262 | - {
|
|
| 252 | + public function getName() { |
|
| 263 | 253 | if (!$this->name) {
|
| 264 | 254 | return uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
|
| 265 | 255 | } |
@@ -272,8 +262,7 @@ discard block |
||
| 272 | 262 | * |
| 273 | 263 | * @return string |
| 274 | 264 | */ |
| 275 | - public function getFullPath() |
|
| 276 | - {
|
|
| 265 | + public function getFullPath() { |
|
| 277 | 266 | $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime; |
| 278 | 267 | return $this->fullPath; |
| 279 | 268 | } |
@@ -283,8 +272,7 @@ discard block |
||
| 283 | 272 | * |
| 284 | 273 | * @return int |
| 285 | 274 | */ |
| 286 | - public function getSize() |
|
| 287 | - {
|
|
| 275 | + public function getSize() { |
|
| 288 | 276 | return (int) $this->_files["size"]; |
| 289 | 277 | } |
| 290 | 278 | |
@@ -293,8 +281,7 @@ discard block |
||
| 293 | 281 | * |
| 294 | 282 | * @return int |
| 295 | 283 | */ |
| 296 | - public function getHeight() |
|
| 297 | - {
|
|
| 284 | + public function getHeight() { |
|
| 298 | 285 | if ($this->height != null) {
|
| 299 | 286 | return $this->height; |
| 300 | 287 | } |
@@ -308,8 +295,7 @@ discard block |
||
| 308 | 295 | * |
| 309 | 296 | * @return int |
| 310 | 297 | */ |
| 311 | - public function getWidth() |
|
| 312 | - {
|
|
| 298 | + public function getWidth() { |
|
| 313 | 299 | if ($this->width != null) {
|
| 314 | 300 | return $this->width; |
| 315 | 301 | } |
@@ -323,8 +309,7 @@ discard block |
||
| 323 | 309 | * |
| 324 | 310 | * @return string |
| 325 | 311 | */ |
| 326 | - public function getLocation() |
|
| 327 | - {
|
|
| 312 | + public function getLocation() { |
|
| 328 | 313 | if(!$this->location){
|
| 329 | 314 | $this->setLocation(); |
| 330 | 315 | } |
@@ -337,8 +322,7 @@ discard block |
||
| 337 | 322 | * |
| 338 | 323 | * @return string |
| 339 | 324 | */ |
| 340 | - public function getJson() |
|
| 341 | - {
|
|
| 325 | + public function getJson() { |
|
| 342 | 326 | return json_encode($this->serialize); |
| 343 | 327 | } |
| 344 | 328 | |
@@ -347,8 +331,7 @@ discard block |
||
| 347 | 331 | * |
| 348 | 332 | * @return string |
| 349 | 333 | */ |
| 350 | - public function getMime() |
|
| 351 | - {
|
|
| 334 | + public function getMime() { |
|
| 352 | 335 | return $this->mime; |
| 353 | 336 | } |
| 354 | 337 | |
@@ -357,7 +340,7 @@ discard block |
||
| 357 | 340 | * |
| 358 | 341 | * @return string|bool |
| 359 | 342 | */ |
| 360 | - public function getError(){
|
|
| 343 | + public function getError() { |
|
| 361 | 344 | return $this->error != "" ? $this->error : false; |
| 362 | 345 | } |
| 363 | 346 | |
@@ -366,8 +349,7 @@ discard block |
||
| 366 | 349 | * |
| 367 | 350 | * @param $e int error constant |
| 368 | 351 | */ |
| 369 | - protected function uploadErrors($e) |
|
| 370 | - {
|
|
| 352 | + protected function uploadErrors($e) { |
|
| 371 | 353 | $errors = $this->error_messages['upload']; |
| 372 | 354 | return $errors[$e]; |
| 373 | 355 | } |
@@ -378,8 +360,7 @@ discard block |
||
| 378 | 360 | * |
| 379 | 361 | * @return $this|bool |
| 380 | 362 | */ |
| 381 | - public function upload() |
|
| 382 | - {
|
|
| 363 | + public function upload() { |
|
| 383 | 364 | /* modify variable names for convenience */ |
| 384 | 365 | $image = $this; |
| 385 | 366 | $files = $this->_files; |
@@ -462,8 +443,7 @@ discard block |
||
| 462 | 443 | * |
| 463 | 444 | * @return bool |
| 464 | 445 | */ |
| 465 | - public function moveUploadedFile($tmp_name, $destination) |
|
| 466 | - {
|
|
| 446 | + public function moveUploadedFile($tmp_name, $destination) { |
|
| 467 | 447 | return move_uploaded_file($tmp_name, $destination); |
| 468 | 448 | } |
| 469 | 449 | } |
@@ -134,18 +134,18 @@ discard block |
||
| 134 | 134 | * @param mixed $offset |
| 135 | 135 | * @param mixed $value |
| 136 | 136 | */ |
| 137 | - public function offsetSet($offset, $value){}
|
|
| 137 | + public function offsetSet($offset, $value) {}
|
|
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | 140 | * @param mixed $offset |
| 141 | 141 | * @return null |
| 142 | 142 | */ |
| 143 | - public function offsetExists($offset){}
|
|
| 143 | + public function offsetExists($offset) {}
|
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @param mixed $offset |
| 147 | 147 | */ |
| 148 | - public function offsetUnset($offset){}
|
|
| 148 | + public function offsetUnset($offset) {}
|
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Gets array value \ArrayAccess |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | public function setLocation($dir = "bulletproof", $permission = 0666) |
| 223 | 223 | {
|
| 224 | 224 | if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
|
| 225 | - $createFolder = @mkdir("" . $dir, (int) $permission, true);
|
|
| 225 | + $createFolder = @mkdir("".$dir, (int) $permission, true);
|
|
| 226 | 226 | if (!$createFolder) {
|
| 227 | 227 | $this->error = sprintf($this->error_messages['location'], $dir); |
| 228 | 228 | return; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function setErrorMessages($new_error_messages) |
| 258 | 258 | {
|
| 259 | - if($new_array = array_replace_recursive($this->error_messages, $new_error_messages)) {
|
|
| 259 | + if ($new_array = array_replace_recursive($this->error_messages, $new_error_messages)) {
|
|
| 260 | 260 | $this->error_messages = $new_array; |
| 261 | 261 | }; |
| 262 | 262 | return $this; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | public function getName() |
| 271 | 271 | {
|
| 272 | 272 | if (!$this->name) {
|
| 273 | - return uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
|
|
| 273 | + return uniqid(true)."_".str_shuffle(implode(range("e", "q")));
|
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | return $this->name; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | public function getFullPath() |
| 285 | 285 | {
|
| 286 | - $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime; |
|
| 286 | + $this->fullPath = $this->location."/".$this->name.".".$this->mime; |
|
| 287 | 287 | return $this->fullPath; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | public function getLocation() |
| 336 | 336 | {
|
| 337 | - if(!$this->location){
|
|
| 337 | + if (!$this->location) {
|
|
| 338 | 338 | $this->setLocation(); |
| 339 | 339 | } |
| 340 | 340 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * |
| 367 | 367 | * @return string|bool |
| 368 | 368 | */ |
| 369 | - public function getError(){
|
|
| 369 | + public function getError() {
|
|
| 370 | 370 | return $this->error != "" ? $this->error : false; |
| 371 | 371 | } |
| 372 | 372 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | $files = $this->_files; |
| 395 | 395 | |
| 396 | 396 | /* check if php_exif is enabled */ |
| 397 | - if(!function_exists('exif_imagetype')){
|
|
| 397 | + if (!function_exists('exif_imagetype')) {
|
|
| 398 | 398 | $image->error = "Function 'exif_imagetype' Not found. Please enable \"php_exif\" in your PHP.ini"; |
| 399 | 399 | return null; |
| 400 | 400 | } |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | list($minSize, $maxSize) = $image->size; |
| 410 | 410 | |
| 411 | 411 | /* check for common upload errors */ |
| 412 | - if($image->error = $image->uploadErrors($files["error"])){
|
|
| 412 | + if ($image->error = $image->uploadErrors($files["error"])) {
|
|
| 413 | 413 | return null; |
| 414 | 414 | } |
| 415 | 415 | |
@@ -439,13 +439,13 @@ discard block |
||
| 439 | 439 | return null; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - if($image->height < 4 || $image->width < 4){
|
|
| 442 | + if ($image->height < 4 || $image->width < 4) {
|
|
| 443 | 443 | $image->error = $this->error_messages['too_small']; |
| 444 | 444 | return null; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /* set and get folder name */ |
| 448 | - $image->fullPath = $image->location. "/" . $image->name . "." . $image->mime; |
|
| 448 | + $image->fullPath = $image->location."/".$image->name.".".$image->mime; |
|
| 449 | 449 | |
| 450 | 450 | /* gather image info for json storage */ |
| 451 | 451 | $image->serialize = array( |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - $image->error = $this->error_messages['unknown']; |
|
| 468 | + $image->error = $this->error_messages['unknown']; |
|
| 469 | 469 | return false; |
| 470 | 470 | } |
| 471 | 471 | |