Completed
Push — master ( 78d413...ee1e20 )
by Jared
03:14
created
lib/image/timber-image-operation-resize.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 		$this->w = $w;
22 22
 		$this->h = $h;
23 23
 		// Sanitize crop position
24
-		$allowed_crop_positions = array( 'default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center' );
25
-		if ( $crop !== false && !in_array( $crop, $allowed_crop_positions ) ) {
24
+		$allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center');
25
+		if ( $crop !== false && !in_array($crop, $allowed_crop_positions) ) {
26 26
 			$crop = $allowed_crop_positions[0];
27 27
 		}
28 28
 		$this->crop = $crop;
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 		if ( $this->h ) {
43 43
 			$h = $this->h;
44 44
 		}
45
-		$result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ( $this->crop ? $this->crop : 'f' ); // Crop will be either user named or f (false)
46
-		if($src_extension) {
47
-			$result .= '.'.$src_extension;
45
+		$result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ($this->crop ? $this->crop : 'f'); // Crop will be either user named or f (false)
46
+		if ( $src_extension ) {
47
+			$result .= '.' . $src_extension;
48 48
 		}
49 49
 		return $result;
50 50
 	}
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param string $load_filename
54 54
 	 * @param string $save_filename
55 55
 	 */
56
-	protected function run_animated_gif( $load_filename, $save_filename ) {
57
-		$image = wp_get_image_editor( $load_filename );
56
+	protected function run_animated_gif($load_filename, $save_filename) {
57
+		$image = wp_get_image_editor($load_filename);
58 58
 		$current_size = $image->get_size();
59 59
 		$src_w = $current_size['width'];
60 60
 		$src_h = $current_size['height'];
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		}
66 66
 		$image = new Imagick($load_filename);
67 67
 		$image = $image->coalesceImages();
68
-		$crop = self::get_target_sizes( $load_filename );
68
+		$crop = self::get_target_sizes($load_filename);
69 69
 		foreach ($image as $frame) {
70 70
 			$frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']);
71 71
 			$frame->thumbnailImage($w, $h);
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 		return $image->writeImages($save_filename, true);
76 76
 	}
77 77
 
78
-	protected function get_target_sizes( $load_filename ) {
79
-		$image = wp_get_image_editor( $load_filename );
78
+	protected function get_target_sizes($load_filename) {
79
+		$image = wp_get_image_editor($load_filename);
80 80
 		$w = $this->w;
81 81
 		$h = $this->h;
82 82
 		$crop = $this->crop;
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 		$src_h = $current_size['height'];
87 87
 		$src_ratio = $src_w / $src_h;
88 88
 		if ( !$h ) {
89
-			$h = round( $w / $src_ratio );
89
+			$h = round($w / $src_ratio);
90 90
 		}
91 91
 		if ( !$w ) {
92 92
 			//the user wants to resize based on constant height
93
-			$w = round( $h * $src_ratio );
93
+			$w = round($h * $src_ratio);
94 94
 		}
95 95
 		if ( !$crop ) {
96 96
 			return array(
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 		$src_wt = $src_h * $dest_ratio;
105 105
 		$src_ht = $src_w / $dest_ratio;
106 106
 		$src_x = $src_w / 2 - $src_wt / 2;
107
-		$src_y = ( $src_h - $src_ht ) / 6;
107
+		$src_y = ($src_h - $src_ht) / 6;
108 108
 		//now specific overrides based on options:
109
-		switch ( $crop ) {
109
+		switch ($crop) {
110 110
 			case 'center':
111 111
 				// Get source x and y
112
-				$src_x = round( ( $src_w - $src_wt ) / 2 );
113
-				$src_y = round( ( $src_h - $src_ht ) / 2 );
112
+				$src_x = round(($src_w - $src_wt) / 2);
113
+				$src_y = round(($src_h - $src_ht) / 2);
114 114
 				break;
115 115
 
116 116
 			case 'top':
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 				break;
123 123
 
124 124
 			case 'top-center':
125
-				$src_y = round( ( $src_h - $src_ht ) / 4 );
125
+				$src_y = round(($src_h - $src_ht) / 4);
126 126
 				break;
127 127
 
128 128
 			case 'bottom-center':
129
-				$src_y = $src_h - $src_ht - round( ( $src_h - $src_ht ) / 4 );
129
+				$src_y = $src_h - $src_ht - round(($src_h - $src_ht) / 4);
130 130
 				break;
131 131
 
132 132
 			case 'left':
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 				break;
139 139
 		}
140 140
 		// Crop the image
141
-		return ( $dest_ratio > $src_ratio )
141
+		return ($dest_ratio > $src_ratio)
142 142
 			? array(
143 143
 				'x' => 0, 'y' => $src_y,
144 144
 				'src_w' => $src_w, 'src_h' => $src_ht,
@@ -168,35 +168,35 @@  discard block
 block discarded – undo
168 168
 			//return if successful
169 169
 			//proceed if not
170 170
 			$gif = self::run_animated_gif($load_filename, $save_filename);
171
-			if ($gif) {
171
+			if ( $gif ) {
172 172
 				return true;
173 173
 			}
174 174
 		}
175
-		$image = wp_get_image_editor( $load_filename );
176
-		if ( !is_wp_error( $image ) ) {
177
-			$crop = self::get_target_sizes( $load_filename );
178
-			$image->crop( 	$crop['x'],
175
+		$image = wp_get_image_editor($load_filename);
176
+		if ( !is_wp_error($image) ) {
177
+			$crop = self::get_target_sizes($load_filename);
178
+			$image->crop($crop['x'],
179 179
 							$crop['y'],
180 180
 							$crop['src_w'],
181 181
 							$crop['src_h'],
182 182
 							$crop['target_w'],
183 183
 							$crop['target_h']
184 184
 			);
185
-			$result = $image->save( $save_filename );
186
-			if ( is_wp_error( $result ) ) {
185
+			$result = $image->save($save_filename);
186
+			if ( is_wp_error($result) ) {
187 187
 				// @codeCoverageIgnoreStart
188
-				TimberHelper::error_log( 'Error resizing image' );
189
-				TimberHelper::error_log( $result );
188
+				TimberHelper::error_log('Error resizing image');
189
+				TimberHelper::error_log($result);
190 190
 				return false;
191 191
 				// @codeCoverageIgnoreEnd
192 192
 			} else {
193 193
 				return true;
194 194
 			}
195
-		} else if ( isset( $image->error_data['error_loading_image'] ) ) {
195
+		} else if ( isset($image->error_data['error_loading_image']) ) {
196 196
 			// @codeCoverageIgnoreStart
197
-			TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
197
+			TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
198 198
 		} else {
199
-			TimberHelper::error_log( $image );
199
+			TimberHelper::error_log($image);
200 200
 			// @codeCoverageIgnoreEnd
201 201
 		}
202 202
 	}
Please login to merge, or discard this patch.