Customize: Respect aspect ratio on cropped images.

Takes into account whether the control supports `flex_width` and/or
`flex_height` and adjusts destination measurements accordingly.

Fixes #36318.



git-svn-id: https://develop.svn.wordpress.org/trunk@37113 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland 2016-03-30 15:13:34 +00:00
parent 0e99aea684
commit 783102fcdc
2 changed files with 22 additions and 12 deletions

View File

@ -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', {

View File

@ -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', {