From db17c157783f0bc66c4881170c467821285dd733 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 8 Apr 2016 01:22:06 +0000 Subject: [PATCH] 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 --- src/wp-admin/js/customize-controls.js | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 5c0d0a40fa..5c21af6be4 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -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;