Completed
Pull Request — master (#793)
by Jared
03:28 queued 29s
created
lib/image/timber-image-operation-resize.php 1 patch
Spacing   +27 added lines, -27 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' );
25
-		if ( $crop !== false && !in_array( $crop, $allowed_crop_positions ) ) {
24
+		$allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right');
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,15 +42,15 @@  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
 	}
51 51
 
52
-	protected function run_animated_gif( $load_filename, $save_filename ) {
53
-		$image = wp_get_image_editor( $load_filename );
52
+	protected function run_animated_gif($load_filename, $save_filename) {
53
+		$image = wp_get_image_editor($load_filename);
54 54
 		$current_size = $image->get_size();
55 55
 		$src_w = $current_size['width'];
56 56
 		$src_h = $current_size['height'];
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		}
62 62
 		$image = new Imagick($load_filename);
63 63
 		$image = $image->coalesceImages();
64
-		$crop = self::get_target_sizes( $load_filename );
64
+		$crop = self::get_target_sizes($load_filename);
65 65
 		foreach ($image as $frame) {
66 66
 			$frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']);
67 67
 			$frame->thumbnailImage($w, $h);
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 		return $image->writeImages($save_filename, true);
72 72
 	}
73 73
 
74
-	protected function get_target_sizes( $load_filename ) {
75
-		$image = wp_get_image_editor( $load_filename );
74
+	protected function get_target_sizes($load_filename) {
75
+		$image = wp_get_image_editor($load_filename);
76 76
 		$w = $this->w;
77 77
 		$h = $this->h;
78 78
 		$crop = $this->crop;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 		$src_h = $current_size['height'];
83 83
 		$src_ratio = $src_w / $src_h;
84 84
 		if ( !$h ) {
85
-			$h = round( $w / $src_ratio );
85
+			$h = round($w / $src_ratio);
86 86
 		}
87 87
 		if ( !$w ) {
88 88
 			//the user wants to resize based on constant height
89
-			$w = round( $h * $src_ratio );
89
+			$w = round($h * $src_ratio);
90 90
 		}
91 91
 		if ( !$crop ) {
92 92
 			return array(
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 		$src_wt = $src_h * $dest_ratio;
101 101
 		$src_ht = $src_w / $dest_ratio;
102 102
 		$src_x = $src_w / 2 - $src_wt / 2;
103
-		$src_y = ( $src_h - $src_ht ) / 6;
103
+		$src_y = ($src_h - $src_ht) / 6;
104 104
 		//now specific overrides based on options:
105 105
 		if ( $crop == 'center' ) {
106 106
 			// Get source x and y
107
-			$src_x = round( ( $src_w - $src_wt ) / 2 );
108
-			$src_y = round( ( $src_h - $src_ht ) / 2 );
107
+			$src_x = round(($src_w - $src_wt) / 2);
108
+			$src_y = round(($src_h - $src_ht) / 2);
109 109
 		} else if ( $crop == 'top' ) {
110 110
 			$src_y = 0;
111 111
 		} else if ( $crop == 'bottom' ) {
@@ -147,35 +147,35 @@  discard block
 block discarded – undo
147 147
 			//return if successful
148 148
 			//proceed if not
149 149
 			$gif = self::run_animated_gif($load_filename, $save_filename);
150
-			if ($gif) {
150
+			if ( $gif ) {
151 151
 				return true;
152 152
 			}
153 153
 		}
154
-		$image = wp_get_image_editor( $load_filename );
155
-		if ( !is_wp_error( $image ) ) {
156
-			$crop = self::get_target_sizes( $load_filename );
157
-			$image->crop( 	$crop['x'],
154
+		$image = wp_get_image_editor($load_filename);
155
+		if ( !is_wp_error($image) ) {
156
+			$crop = self::get_target_sizes($load_filename);
157
+			$image->crop($crop['x'],
158 158
 							$crop['y'],
159 159
 							$crop['src_w'],
160 160
 							$crop['src_h'],
161 161
 							$crop['target_w'],
162 162
 							$crop['target_h']
163 163
 			);
164
-			$result = $image->save( $save_filename );
165
-			if ( is_wp_error( $result ) ) {
164
+			$result = $image->save($save_filename);
165
+			if ( is_wp_error($result) ) {
166 166
 				// @codeCoverageIgnoreStart
167
-				TimberHelper::error_log( 'Error resizing image' );
168
-				TimberHelper::error_log( $result );
167
+				TimberHelper::error_log('Error resizing image');
168
+				TimberHelper::error_log($result);
169 169
 				return false;
170 170
 				// @codeCoverageIgnoreEnd
171 171
 			} else {
172 172
 				return true;
173 173
 			}
174
-		} else if ( isset( $image->error_data['error_loading_image'] ) ) {
174
+		} else if ( isset($image->error_data['error_loading_image']) ) {
175 175
 			// @codeCoverageIgnoreStart
176
-			TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
176
+			TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
177 177
 		} else {
178
-			TimberHelper::error_log( $image );
178
+			TimberHelper::error_log($image);
179 179
 			// @codeCoverageIgnoreEnd
180 180
 		}
181 181
 	}
Please login to merge, or discard this patch.