diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 7be686827a..0e1ea805ec 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -400,13 +400,18 @@ var Controller = wp.media.controller, CustomizeImageCropper = Controller.Cropper.extend({ doCrop: function( attachment ) { var cropDetails = attachment.get( 'cropDetails' ), - control = this.get( 'control' ); + control = this.get( 'control' ), + ratio = cropDetails.width / cropDetails.height; - if ( ! control.params.flex_width ) { - cropDetails.dst_width = control.params.width; - } - if ( ! control.params.flex_height ) { - cropDetails.dst_height = control.params.height; + // Use crop measurements when flexible in both directions. + if ( control.params.flex_width && control.params.flex_height ) { + cropDetails.dst_width = cropDetails.width; + cropDetails.dst_height = cropDetails.height; + + // Constrain flexible side based on image ratio and size of the fixed side. + } else { + cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width; + cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height; } return wp.ajax.post( 'crop-image', { diff --git a/src/wp-includes/js/media/controllers/customize-image-cropper.js b/src/wp-includes/js/media/controllers/customize-image-cropper.js index df2d77baca..3456ba36ff 100644 --- a/src/wp-includes/js/media/controllers/customize-image-cropper.js +++ b/src/wp-includes/js/media/controllers/customize-image-cropper.js @@ -14,13 +14,18 @@ var Controller = wp.media.controller, CustomizeImageCropper = Controller.Cropper.extend({ doCrop: function( attachment ) { var cropDetails = attachment.get( 'cropDetails' ), - control = this.get( 'control' ); + control = this.get( 'control' ), + ratio = cropDetails.width / cropDetails.height; - if ( ! control.params.flex_width ) { - cropDetails.dst_width = control.params.width; - } - if ( ! control.params.flex_height ) { - cropDetails.dst_height = control.params.height; + // Use crop measurements when flexible in both directions. + if ( control.params.flex_width && control.params.flex_height ) { + cropDetails.dst_width = cropDetails.width; + cropDetails.dst_height = cropDetails.height; + + // Constrain flexible side based on image ratio and size of the fixed side. + } else { + cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width; + cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height; } return wp.ajax.post( 'crop-image', {