From e971dd25bca95be47d56c38e466c6e97ffb829bd Mon Sep 17 00:00:00 2001 From: rvpatel Date: Wed, 14 Oct 2026 21:03:47 +0530 Subject: [PATCH 1/2] Administration: Create site icon sizes for exact-size images in General Settings. When an image that already has the required site icon dimensions (512x512) is selected in Settings > General, the crop step is skipped and the original image is saved as the site icon, so the site icon sizes (32, 64, 180, 192 and 270) are never generated. Send the image through the crop-image request with the `site-icon` context, as the Customizer already does, so the site icon and its sizes are created. See #66309. --- src/js/_enqueues/admin/site-icon.js | 36 ++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/js/_enqueues/admin/site-icon.js b/src/js/_enqueues/admin/site-icon.js index 59a098dc08aac..6e8c03f64ed8e 100644 --- a/src/js/_enqueues/admin/site-icon.js +++ b/src/js/_enqueues/admin/site-icon.js @@ -117,17 +117,37 @@ // When an image is selected, run a callback. frame.on( 'select', function () { // Grab the selected attachment. - var attachment = frame.state().get( 'selection' ).first(); + var attachment = frame.state().get( 'selection' ).first(), + size = $el.data( 'size' ); if ( - attachment.attributes.height === $el.data( 'size' ) && - $el.data( 'size' ) === attachment.attributes.width + attachment.attributes.height === size && + size === attachment.attributes.width ) { - switchToUpdate( attachment.attributes ); - frame.close(); - - // Set the value of the hidden input to the attachment id. - $hiddenDataField.val( attachment.id ); + /* + * The image doesn't need cropping, but it still goes through the crop + * request so that the site icon and its additional sizes are created. + */ + wp.ajax + .post( 'crop-image', { + nonce: attachment.get( 'nonces' ).edit, + id: attachment.id, + context: 'site-icon', + cropDetails: { + x1: 0, + y1: 0, + width: size, + height: size, + dst_width: size, + dst_height: size, + }, + } ) + .done( function ( croppedImage ) { + frame.trigger( 'cropped', croppedImage ); + } ) + .fail( function () { + frame.trigger( 'content:error:crop' ); + } ); } else { frame.setState( 'cropper' ); } From 418052efd307dbdab3c19849d60bfbbc0f4fcab8 Mon Sep 17 00:00:00 2001 From: rvpatel Date: Wed, 11 Nov 2026 19:03:39 +0530 Subject: [PATCH 2/2] Administration: Allow skipping the site icon crop for square images. In Settings > General, show the "Skip cropping" button for square images, as the Customizer does. Skipping still sends the whole image through the `crop-image` request with the `site-icon` context, so the site icon sizes are created. See #64020, #66309. --- src/js/_enqueues/admin/site-icon.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/admin/site-icon.js b/src/js/_enqueues/admin/site-icon.js index 6e8c03f64ed8e..33898175e5204 100644 --- a/src/js/_enqueues/admin/site-icon.js +++ b/src/js/_enqueues/admin/site-icon.js @@ -24,9 +24,10 @@ * @since 6.5.0 * * @param {Object} attachment The attachment object representing the image. + * @param {Object} controller The cropper controller. * @return {Object} The image selection options. */ - function calculateImageSelectOptions( attachment ) { + function calculateImageSelectOptions( attachment, controller ) { var realWidth = attachment.get( 'width' ), realHeight = attachment.get( 'height' ), xInit = 512, @@ -38,6 +39,20 @@ y1, imgSelectOptions; + /* + * Square images can skip cropping. "Skip Cropping" still sends the whole + * image through the crop request, so the site icon sizes are created. + */ + controller.set( 'hasRequiredAspectRatio', realWidth === realHeight ); + controller.set( 'suggestedCropSize', { + width: realWidth, + height: realHeight, + x1: 0, + y1: 0, + x2: xInit, + y2: yInit, + } ); + if ( realWidth / realHeight > ratio ) { yInit = realHeight; xInit = yInit * ratio;