diff --git a/src/wp-admin/includes/image-edit.php b/src/wp-admin/includes/image-edit.php
index e1ae86b607..e9de8b73dd 100644
a
|
b
|
function wp_save_image( $post_id ) { |
931 | 931 | ); |
932 | 932 | } |
933 | 933 | |
934 | | $meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) ); |
| 934 | $meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes, $post_id ) ); |
935 | 935 | } |
936 | 936 | |
937 | 937 | unset( $img ); |
diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php
index d0a2954e5f..60467d1451 100644
a
|
b
|
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
142 | 142 | $editor = wp_get_image_editor( $file ); |
143 | 143 | |
144 | 144 | if ( ! is_wp_error( $editor ) ) { |
145 | | $metadata['sizes'] = $editor->multi_resize( $sizes ); |
| 145 | $metadata['sizes'] = $editor->multi_resize( $sizes, $attachment_id ); |
146 | 146 | } |
147 | 147 | } else { |
148 | 148 | $metadata['sizes'] = array(); |
… |
… |
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
282 | 282 | unset( $uploaded['path'] ); |
283 | 283 | |
284 | 284 | if ( ! is_wp_error( $editor ) ) { |
285 | | $metadata['sizes'] = $editor->multi_resize( $sizes ); |
| 285 | $metadata['sizes'] = $editor->multi_resize( $sizes, $attachment_id ); |
286 | 286 | $metadata['sizes']['full'] = $uploaded; |
287 | 287 | } |
288 | 288 | } |
diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php
index 72fb04ee72..c88d5e4c30 100644
a
|
b
|
class WP_Image_Editor_GD extends WP_Image_Editor { |
149 | 149 | * @param int|null $max_w Image width. |
150 | 150 | * @param int|null $max_h Image height. |
151 | 151 | * @param bool $crop |
| 152 | * @param int $attachment_id |
152 | 153 | * @return true|WP_Error |
153 | 154 | */ |
154 | | public function resize( $max_w, $max_h, $crop = false ) { |
| 155 | public function resize( $max_w, $max_h, $crop = false, $attachment_id = 0 ) { |
155 | 156 | if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) { |
156 | 157 | return true; |
157 | 158 | } |
158 | 159 | |
159 | | $resized = $this->_resize( $max_w, $max_h, $crop ); |
| 160 | $resized = $this->_resize( $max_w, $max_h, $crop, $attachment_id ); |
160 | 161 | |
161 | 162 | if ( is_resource( $resized ) ) { |
162 | 163 | imagedestroy( $this->image ); |
… |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
174 | 175 | * @param int $max_w |
175 | 176 | * @param int $max_h |
176 | 177 | * @param bool|array $crop |
| 178 | * @param int $attachment_id |
177 | 179 | * @return resource|WP_Error |
178 | 180 | */ |
179 | | protected function _resize( $max_w, $max_h, $crop = false ) { |
180 | | $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
| 181 | protected function _resize( $max_w, $max_h, $crop = false, $attachment_id = 0 ) { |
| 182 | $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop, $attachment_id ); |
181 | 183 | if ( ! $dims ) { |
182 | 184 | return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ), $this->file ); |
183 | 185 | } |
… |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
212 | 214 | * @type int $width Image width. Optional if `$height` is specified. |
213 | 215 | * @type int $height Image height. Optional if `$width` is specified. |
214 | 216 | * @type bool $crop Optional. Whether to crop the image. Default false. |
| 217 | * @type int $attachment_id. Optional. Attachment id to resize. |
215 | 218 | * } |
216 | 219 | * } |
217 | 220 | * @return array An array of resized images' metadata by size. |
218 | 221 | */ |
219 | | public function multi_resize( $sizes ) { |
| 222 | public function multi_resize( $sizes, $attachment_id = 0 ) { |
220 | 223 | $metadata = array(); |
221 | 224 | $orig_size = $this->size; |
222 | 225 | |
… |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
236 | 239 | $size_data['crop'] = false; |
237 | 240 | } |
238 | 241 | |
239 | | $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); |
| 242 | $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'], $attachment_id ); |
240 | 243 | $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); |
241 | 244 | |
242 | 245 | if ( ! is_wp_error( $image ) && ! $duplicate ) { |
diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php
index abb215038b..a088ed86fa 100644
a
|
b
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
249 | 249 | * @param int|null $max_w Image width. |
250 | 250 | * @param int|null $max_h Image height. |
251 | 251 | * @param bool $crop |
| 252 | * @param int $attachment_id Attachment id to resize. |
252 | 253 | * @return bool|WP_Error |
253 | 254 | */ |
254 | | public function resize( $max_w, $max_h, $crop = false ) { |
| 255 | public function resize( $max_w, $max_h, $crop = false, $attachment_id = 0 ) { |
255 | 256 | if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) { |
256 | 257 | return true; |
257 | 258 | } |
258 | 259 | |
259 | | $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
| 260 | $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop, $attachment_id ); |
260 | 261 | if ( ! $dims ) { |
261 | 262 | return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ) ); |
262 | 263 | } |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
425 | 426 | * @type int $width Image width. Optional if `$height` is specified. |
426 | 427 | * @type int $height Image height. Optional if `$width` is specified. |
427 | 428 | * @type bool $crop Optional. Whether to crop the image. Default false. |
| 429 | * @type int $attachment_id. Optional. Attachment id to resize. |
428 | 430 | * } |
429 | 431 | * } |
430 | 432 | * @return array An array of resized images' metadata by size. |
431 | 433 | */ |
432 | | public function multi_resize( $sizes ) { |
| 434 | public function multi_resize( $sizes, $attachment_id = 0 ) { |
433 | 435 | $metadata = array(); |
434 | 436 | $orig_size = $this->size; |
435 | 437 | $orig_image = $this->image->getImage(); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
454 | 456 | $size_data['crop'] = false; |
455 | 457 | } |
456 | 458 | |
457 | | $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); |
| 459 | $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'], $attachment_id ); |
458 | 460 | $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); |
459 | 461 | |
460 | 462 | if ( ! is_wp_error( $resize_result ) && ! $duplicate ) { |
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php
index 26dd78d230..f6252f615b 100644
a
|
b
|
abstract class WP_Image_Editor { |
110 | 110 | * @type int $width Image width. |
111 | 111 | * @type int $height Image height. |
112 | 112 | * @type bool $crop Optional. Whether to crop the image. Default false. |
| 113 | * @type int $attachment_id. Optional. Attachment id to resize. |
113 | 114 | * } |
114 | 115 | * } |
115 | 116 | * @return array An array of resized images metadata by size. |
116 | 117 | */ |
117 | | abstract public function multi_resize( $sizes ); |
| 118 | abstract public function multi_resize( $sizes, $attachment_id = 0 ); |
118 | 119 | |
119 | 120 | /** |
120 | 121 | * Crops Image. |
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index bb2e0b8e27..a74e7bd9d3 100644
a
|
b
|
function wp_constrain_dimensions( $current_width, $current_height, $max_width = |
491 | 491 | * @param int $dest_h New height in pixels. |
492 | 492 | * @param bool|array $crop Optional. Whether to crop image to specified width and height or resize. |
493 | 493 | * An array can specify positioning of the crop area. Default false. |
| 494 | * @param int $attachment_id. Attachment id to resize. |
494 | 495 | * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`. |
495 | 496 | */ |
496 | | function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) { |
| 497 | function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false, $attachment_id = 0 ) { |
497 | 498 | |
498 | 499 | if ( $orig_w <= 0 || $orig_h <= 0 ) { |
499 | 500 | return false; |
… |
… |
function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = fa |
519 | 520 | * @param bool|array $crop Whether to crop image to specified width and height or resize. |
520 | 521 | * An array can specify positioning of the crop area. Default false. |
521 | 522 | */ |
522 | | $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); |
| 523 | $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop, $attachment_id ); |
523 | 524 | if ( null !== $output ) { |
524 | 525 | return $output; |
525 | 526 | } |