@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | if ($thumbnail_aspect_ratio < $source_aspect_ratio) { |
| 66 | 66 | $src_h = $imgHeight; |
| 67 | 67 | $src_w = $imgHeight * $thumbnail_aspect_ratio; |
| 68 | - $src_x = (int) (($imgWidth - $src_w)/2); |
|
| 68 | + $src_x = (int) (($imgWidth - $src_w) / 2); |
|
| 69 | 69 | $src_y = 0; |
| 70 | 70 | } else { |
| 71 | 71 | $src_w = $imgWidth; |
| 72 | 72 | $src_h = (int) ($imgWidth / $thumbnail_aspect_ratio); |
| 73 | 73 | $src_x = 0; |
| 74 | - $src_y = (int) (($imgHeight - $src_h)/2); |
|
| 74 | + $src_y = (int) (($imgHeight - $src_h) / 2); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Checks whether image upsizing is enabled |
@@ -86,26 +86,26 @@ discard block |
||
| 86 | 86 | if ($newHeight > $newHeightOrig) { |
| 87 | 87 | $newHeight = $newHeightOrig; |
| 88 | 88 | $src_h = $newHeight; |
| 89 | - $src_y = (int) (($imgHeight - $src_h)/2); |
|
| 89 | + $src_y = (int) (($imgHeight - $src_h) / 2); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $src_x=0; |
|
| 92 | + $src_x = 0; |
|
| 93 | 93 | $src_w = $imgWidth; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // If the given height is larger then the image height, then resize it. |
| 97 | 97 | if ($newHeightOrig > $imgHeight) { |
| 98 | 98 | $newHeight = $imgHeight; |
| 99 | - $src_y=0; |
|
| 99 | + $src_y = 0; |
|
| 100 | 100 | $src_h = $imgHeight; |
| 101 | - $src_w = (int) ($src_h * ( $newWidth / $newHeight )); |
|
| 102 | - $src_x = (int) (($imgWidth - $src_w)/2); |
|
| 101 | + $src_w = (int) ($src_h * ($newWidth / $newHeight)); |
|
| 102 | + $src_x = (int) (($imgWidth - $src_w) / 2); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | } else { |
| 106 | 106 | |
| 107 | 107 | // First, calculate the height. |
| 108 | - $height = (int) ($newWidth / $imgWidth * $imgHeight); // 75 |
|
| 108 | + $height = (int) ($newWidth / $imgWidth * $imgHeight); // 75 |
|
| 109 | 109 | |
| 110 | 110 | // If the height is too large, set it to the maximum height and calculate the width. |
| 111 | 111 | if ($height > $newHeight) { |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | 171 | if ($destination !== false) { // checks if was destination provided |
| 172 | - if(substr( $destination, -1 ) == '/' ) { // check whether prowided destination was folder or file. |
|
| 172 | + if (substr($destination, -1) == '/') { // check whether prowided destination was folder or file. |
|
| 173 | 173 | $create = !is_dir($destination) ? @mkdir($destination, $permission, true) : true; // if it was folder, it will crtete it if needed |
| 174 | 174 | if ($create) { |
| 175 | 175 | $path_parts = pathinfo($image); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | $path_parts = pathinfo($destination); |
| 187 | - $create = !is_dir($path_parts['dirname'].'/') ? @mkdir($path_parts['dirname'].'/', $permission, true) : true; |
|
| 187 | + $create = !is_dir($path_parts['dirname'] . '/') ? @mkdir($path_parts['dirname'] . '/', $permission, true) : true; |
|
| 188 | 188 | if (!$create) { |
| 189 | 189 | return false; // TODO: throw error/exception |
| 190 | 190 | } |
@@ -193,35 +193,35 @@ discard block |
||
| 193 | 193 | case "jpeg": |
| 194 | 194 | case "jpg": |
| 195 | 195 | $q = 90; // function's default value - if everything else fails, this is used. |
| 196 | - if( false !== $image ) { |
|
| 197 | - if ((!empty($quality['jpg']['fallback'])) AND ( (int) $quality['jpg']['fallback'] ) AND ( $quality['jpg']['fallback'] > 0 ) AND ( $quality['jpg']['fallback'] <=100 ) ) { |
|
| 196 | + if (false !== $image) { |
|
| 197 | + if ((!empty($quality['jpg']['fallback'])) AND ((int) $quality['jpg']['fallback']) AND ($quality['jpg']['fallback'] > 0) AND ($quality['jpg']['fallback'] <= 100)) { |
|
| 198 | 198 | $q = $quality['jpg']['fallback']; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ((!empty($quality['jpg']['orig'])) AND true ===$quality['jpg']['orig'] ){ |
|
| 202 | - if (extension_loaded('imagick')){ |
|
| 201 | + if ((!empty($quality['jpg']['orig'])) AND true === $quality['jpg']['orig']) { |
|
| 202 | + if (extension_loaded('imagick')) { |
|
| 203 | 203 | $im = new \Imagick($image); |
| 204 | 204 | $q = $im->getImageCompressionQuality(); |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if((!empty($quality['jpg']['max'])) AND $quality['jpg']['max'] < $q ){ |
|
| 208 | + if ((!empty($quality['jpg']['max'])) AND $quality['jpg']['max'] < $q) { |
|
| 209 | 209 | $q = $quality['jpg']['max']; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if((!empty($quality['jpg']['min'])) AND $quality['jpg']['min'] > $q ){ |
|
| 212 | + if ((!empty($quality['jpg']['min'])) AND $quality['jpg']['min'] > $q) { |
|
| 213 | 213 | $q = $quality['jpg']['min']; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | - return imagejpeg($tmp, $destination, $q ); |
|
| 216 | + return imagejpeg($tmp, $destination, $q); |
|
| 217 | 217 | break; |
| 218 | 218 | case "png": |
| 219 | - if ((!empty($quality['png'])) AND ( (int) $quality['png'] ) AND ( $quality['png'] >= -1 ) AND ( $quality['png'] <=9 ) ) { |
|
| 219 | + if ((!empty($quality['png'])) AND ((int) $quality['png']) AND ($quality['png'] >= -1) AND ($quality['png'] <= 9)) { |
|
| 220 | 220 | $q = $quality['png']; |
| 221 | 221 | } else { |
| 222 | 222 | $q = -1; // -1 is zlib's default value which is currently ( 11/2018 ) equal to 6 |
| 223 | 223 | } |
| 224 | - return imagepng($tmp, $destination, $q ); |
|
| 224 | + return imagepng($tmp, $destination, $q); |
|
| 225 | 225 | break; |
| 226 | 226 | case "gif": |
| 227 | 227 | return imagegif($tmp, $destination); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | // check full path of image uploaded |
| 83 | 83 | |
| 84 | - public function testFullpath(){ |
|
| 84 | + public function testFullpath(){ |
|
| 85 | 85 | $this->bulletproof->setLocation('uploads'); |
| 86 | 86 | $this->bulletproof->setName('2012'); |
| 87 | 87 | $this->bulletproof->setMime(['jpeg']); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | // check json return value of image |
| 95 | - public function testJsonOutput(){ |
|
| 95 | + public function testJsonOutput(){ |
|
| 96 | 96 | $upload = $this->bulletproof->setName('we_belive_in_json')->upload(); |
| 97 | 97 | $this->assertSame($upload->getJson(), |
| 98 | 98 | '{"name":"we_belive_in_json","mime":"jpeg","height":345,"width":384,"size":17438,"storage":"uploads","path":"uploads\/we_belive_in_json.jpeg"}'); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function testImageSizeFailWithMsg () { |
| 120 | 120 | $this->bulletproof->setSize(888, 9999); |
| 121 | 121 | $upload = $this->bulletproof->upload(); |
| 122 | - $this->assertEquals($this->bulletproof->getError(), 'Image size should be minumum 888 bytes (0 kb), upto maximum 9999 bytes (9 kb)'); |
|
| 122 | + $this->assertEquals($this->bulletproof->getError(), 'Image size should be minumum 888 bytes (0 kb), upto maximum 9999 bytes (9 kb)'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // check invalid dimension fails with msg |
@@ -28,21 +28,21 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // check if the name provide in the html input is read by bulletproof |
| 31 | - public function testImageNameIsSame () { |
|
| 31 | + public function testImageNameIsSame() { |
|
| 32 | 32 | $this->bulletproof->setName('samayo'); |
| 33 | 33 | $this->assertEquals($this->bulletproof->getName(), 'samayo'); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | // test image accepts certain mime types |
| 38 | - public function testMimeTypes () { |
|
| 38 | + public function testMimeTypes() { |
|
| 39 | 39 | $this->bulletproof->setMime(['jpeg']); |
| 40 | 40 | $upload = $this->bulletproof->upload(); |
| 41 | 41 | $this->assertEquals($upload->getMime(), 'jpeg'); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // check dimensions params |
| 45 | - public function testDimensions () { |
|
| 45 | + public function testDimensions() { |
|
| 46 | 46 | // give it out of range (minimum dimentions than the class requires) |
| 47 | 47 | $this->bulletproof->setDimension(1, 'b'); |
| 48 | 48 | $upload = $this->bulletproof->upload(); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | // check size of the image is correct |
| 54 | - public function testSize () { |
|
| 54 | + public function testSize() { |
|
| 55 | 55 | $this->bulletproof->upload(); |
| 56 | 56 | $this->assertEquals($this->bulletproof->getSize(), 17438); // 17438 is size of the monkey.jpg |
| 57 | 57 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // check if setting image storage is correct |
| 76 | - public function testLocation () { |
|
| 76 | + public function testLocation() { |
|
| 77 | 77 | $this->bulletproof->setLocation('uploads'); |
| 78 | 78 | $this->assertEquals($this->bulletproof->getStorage(), 'uploads'); |
| 79 | 79 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | // check full path of image uploaded |
| 83 | 83 | |
| 84 | - public function testFullpath(){ |
|
| 84 | + public function testFullpath() { |
|
| 85 | 85 | $this->bulletproof->setLocation('uploads'); |
| 86 | 86 | $this->bulletproof->setName('2012'); |
| 87 | 87 | $this->bulletproof->setMime(['jpeg']); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | // check json return value of image |
| 95 | - public function testJsonOutput(){ |
|
| 95 | + public function testJsonOutput() { |
|
| 96 | 96 | $upload = $this->bulletproof->setName('we_belive_in_json')->upload(); |
| 97 | 97 | $this->assertSame($upload->getJson(), |
| 98 | 98 | '{"name":"we_belive_in_json","mime":"jpeg","height":345,"width":384,"size":17438,"storage":"uploads","path":"uploads\/we_belive_in_json.jpeg"}'); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // check invalid mimetype fails |
| 103 | 103 | |
| 104 | - public function testMimeTypeFail () { |
|
| 104 | + public function testMimeTypeFail() { |
|
| 105 | 105 | $this->bulletproof->setMime(['gif']); |
| 106 | 106 | $upload = $this->bulletproof->upload(); |
| 107 | 107 | $this->assertFalse($upload); |
@@ -109,21 +109,21 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | // check invalid mimetype fails with msg |
| 111 | 111 | |
| 112 | - public function testMimeTypeFailWithMsg () { |
|
| 112 | + public function testMimeTypeFailWithMsg() { |
|
| 113 | 113 | $this->bulletproof->setMime(['gif']); |
| 114 | 114 | $upload = $this->bulletproof->upload(); |
| 115 | 115 | $this->assertEquals($this->bulletproof->getError(), 'Invalid File! Only (gif) image types are allowed'); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // check invalid size with msg |
| 119 | - public function testImageSizeFailWithMsg () { |
|
| 119 | + public function testImageSizeFailWithMsg() { |
|
| 120 | 120 | $this->bulletproof->setSize(888, 9999); |
| 121 | 121 | $upload = $this->bulletproof->upload(); |
| 122 | 122 | $this->assertEquals($this->bulletproof->getError(), 'Image size should be minumum 888 bytes (0 kb), upto maximum 9999 bytes (9 kb)'); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // check invalid dimension fails with msg |
| 126 | -public function testImageDimensionFailWithMsg () { |
|
| 126 | +public function testImageDimensionFailWithMsg() { |
|
| 127 | 127 | $this->bulletproof->setDimension(42, 43); |
| 128 | 128 | $this->bulletproof->upload(); |
| 129 | 129 | $this->assertEquals($this->bulletproof->getError(), 'Image height/width should be less than 43/42 pixels'); |
@@ -4,10 +4,10 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class BulletproofTest extends \Bulletproof\Image { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * Return true at this point since we can't upload files |
|
| 9 | - * during test (or can we? I don't know!) |
|
| 10 | - */ |
|
| 7 | + /** |
|
| 8 | + * Return true at this point since we can't upload files |
|
| 9 | + * during test (or can we? I don't know!) |
|
| 10 | + */ |
|
| 11 | 11 | public function isSaved($tmp, $desination) |
| 12 | 12 | { |
| 13 | 13 | return true; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * Prevent class from making new folder |
| 18 | 18 | */ |
| 19 | 19 | public function setLocation($dir = "bulletproof", $optionalPermision = 0666){ |
| 20 | - $this->location = $dir; |
|
| 21 | - return $this; |
|
| 20 | + $this->location = $dir; |
|
| 21 | + return $this; |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | /** |
| 17 | 17 | * Prevent class from making new folder |
| 18 | 18 | */ |
| 19 | - public function setLocation($dir = "bulletproof", $optionalPermision = 0666){ |
|
| 19 | + public function setLocation($dir = "bulletproof", $optionalPermision = 0666) { |
|
| 20 | 20 | $this->location = $dir; |
| 21 | 21 | return $this; |
| 22 | 22 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | // you want to allow, and if so: |
| 24 | 24 | header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); |
| 25 | 25 | header('Access-Control-Allow-Credentials: true'); |
| 26 | - header('Access-Control-Max-Age: 86400'); // cache for 1 day |
|
| 26 | + header('Access-Control-Max-Age: 86400'); // cache for 1 day |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Access-Control headers are received during OPTIONS requests |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | if (is_numeric($val)) { |
| 92 | - $int = (int)$val; |
|
| 93 | - $float = (float)$val; |
|
| 92 | + $int = (int) $val; |
|
| 93 | + $float = (float) $val; |
|
| 94 | 94 | |
| 95 | 95 | $val = ($int == $float) ? $int : $float; |
| 96 | 96 | return $val; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | function get_includes() |
| 179 | 179 | { |
| 180 | - $included = array_values(array_filter(array_map(function ($arr) { |
|
| 180 | + $included = array_values(array_filter(array_map(function($arr) { |
|
| 181 | 181 | if (is_string($arr)) { |
| 182 | 182 | if (strpos($arr, 'vendor')) { |
| 183 | 183 | return ''; |
@@ -15,7 +15,9 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | function cors() |
| 17 | 17 | { |
| 18 | - if (!headers_sent()) return; |
|
| 18 | + if (!headers_sent()) { |
|
| 19 | + return; |
|
| 20 | + } |
|
| 19 | 21 | |
| 20 | 22 | // Allow from any origin |
| 21 | 23 | if (isset($_SERVER['HTTP_ORIGIN'])) { |
@@ -151,7 +153,9 @@ discard block |
||
| 151 | 153 | if (!file_exists(dirname($file))) { |
| 152 | 154 | mkdir(dirname($file)); |
| 153 | 155 | } |
| 154 | - if (file_exists($file)) delete($file); |
|
| 156 | + if (file_exists($file)) { |
|
| 157 | + delete($file); |
|
| 158 | + } |
|
| 155 | 159 | file_put_contents($file, $content, ($append ? FILE_APPEND : 0)); |
| 156 | 160 | } |
| 157 | 161 | |
@@ -19,9 +19,13 @@ |
||
| 19 | 19 | $thePost = $_POST[$name]; |
| 20 | 20 | if ($flag != POST_DEFAULT_FLAG) { |
| 21 | 21 | if ($flag == POST_NOT_NULL) { |
| 22 | - if ($thePost != null) return $thePost; |
|
| 22 | + if ($thePost != null) { |
|
| 23 | + return $thePost; |
|
| 24 | + } |
|
| 23 | 25 | } else if ($flag == POST_NOT_EMPTY) { |
| 24 | - if (!empty($thePost)) return $thePost; |
|
| 26 | + if (!empty($thePost)) { |
|
| 27 | + return $thePost; |
|
| 28 | + } |
|
| 25 | 29 | } |
| 26 | 30 | } else { |
| 27 | 31 | return $thePost; |
@@ -9,7 +9,11 @@ |
||
| 9 | 9 | function current_timestamp($date = null) |
| 10 | 10 | { |
| 11 | 11 | $timestamp = $date; |
| 12 | - if (is_string($date)) $timestamp = strtotime($date); |
|
| 13 | - if (is_null($date)) $timestamp = time(); |
|
| 12 | + if (is_string($date)) { |
|
| 13 | + $timestamp = strtotime($date); |
|
| 14 | + } |
|
| 15 | + if (is_null($date)) { |
|
| 16 | + $timestamp = time(); |
|
| 17 | + } |
|
| 14 | 18 | return date("Y-m-d H:i:s", $timestamp); |
| 15 | 19 | } |