Customizer: fix cropping of small images when setting header image, site icon or logo.

Props obenland.
Fixes #36412.

git-svn-id: https://develop.svn.wordpress.org/trunk@37167 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2016-04-08 01:22:06 +00:00
parent ca5db69c31
commit db17c15778
1 changed files with 17 additions and 11 deletions

View File

@ -2097,22 +2097,22 @@
xInit = parseInt( control.params.width, 10 ),
yInit = parseInt( control.params.height, 10 ),
ratio = xInit / yInit,
xImg = realWidth,
yImg = realHeight,
xImg = xInit,
yImg = yInit,
x1, y1, imgSelectOptions;
controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) );
if ( xImg / yImg > ratio ) {
yInit = yImg;
if ( realWidth / realHeight > ratio ) {
yInit = realHeight;
xInit = yInit * ratio;
} else {
xInit = xImg;
xInit = realWidth;
yInit = xInit / ratio;
}
x1 = ( xImg - xInit ) / 2;
y1 = ( yImg - yInit ) / 2;
x1 = ( realWidth - xInit ) / 2;
y1 = ( realHeight - yInit ) / 2;
imgSelectOptions = {
handles: true,
@ -2121,6 +2121,8 @@
persistent: true,
imageWidth: realWidth,
imageHeight: realHeight,
minWidth: xImg > xInit ? xInit : xImg,
minHeight: yImg > yInit ? yInit : yImg,
x1: x1,
y1: y1,
x2: xInit + x1,
@ -2130,11 +2132,15 @@
if ( flexHeight === false && flexWidth === false ) {
imgSelectOptions.aspectRatio = xInit + ':' + yInit;
}
if ( flexHeight === false ) {
imgSelectOptions.maxHeight = yInit;
if ( true === flexHeight ) {
delete imgSelectOptions.minHeight;
imgSelectOptions.maxWidth = realWidth;
}
if ( flexWidth === false ) {
imgSelectOptions.maxWidth = xInit;
if ( true === flexWidth ) {
delete imgSelectOptions.minWidth;
imgSelectOptions.maxHeight = realHeight;
}
return imgSelectOptions;