@@ -1194,49 +1194,60 @@ export function generateThumbnails( id: QueueItemId ) {
11941194 // Create and sideload the scaled version.
11951195 const { bigImageSizeThreshold } = settings ;
11961196 if ( bigImageSizeThreshold && attachment . id ) {
1197- // Rename sourceFile to match the server attachment filename.
1198- const sourceForScaled = attachment . filename
1199- ? renameFile ( item . sourceFile , attachment . filename )
1200- : item . sourceFile ;
1201-
1202- // Add scaling to queue.
1203- const scaledOperations : Operation [ ] = [
1204- [
1205- OperationType . ResizeCrop ,
1206- {
1207- resize : {
1208- width : bigImageSizeThreshold ,
1209- height : bigImageSizeThreshold ,
1197+ // Check if the image actually exceeds the threshold.
1198+ // Only create a scaled version for images larger than the threshold,
1199+ // matching WordPress core's wp_create_image_subsizes() behavior.
1200+ const bitmap = await createImageBitmap ( item . sourceFile ) ;
1201+ const needsScaling =
1202+ bitmap . width > bigImageSizeThreshold ||
1203+ bitmap . height > bigImageSizeThreshold ;
1204+ bitmap . close ( ) ;
1205+
1206+ if ( needsScaling ) {
1207+ // Rename sourceFile to match the server attachment filename.
1208+ const sourceForScaled = attachment . filename
1209+ ? renameFile ( item . sourceFile , attachment . filename )
1210+ : item . sourceFile ;
1211+
1212+ // Add scaling to queue.
1213+ const scaledOperations : Operation [ ] = [
1214+ [
1215+ OperationType . ResizeCrop ,
1216+ {
1217+ resize : {
1218+ width : bigImageSizeThreshold ,
1219+ height : bigImageSizeThreshold ,
1220+ } ,
1221+ isThresholdResize : true ,
12101222 } ,
1211- isThresholdResize : true ,
1223+ ] ,
1224+ ] ;
1225+
1226+ // Add transcoding if format conversion is configured.
1227+ if ( thumbnailTranscodeOperation ) {
1228+ scaledOperations . push ( thumbnailTranscodeOperation ) ;
1229+ }
1230+
1231+ scaledOperations . push ( OperationType . Upload ) ;
1232+
1233+ dispatch . addSideloadItem ( {
1234+ file : sourceForScaled ,
1235+ onChange : ( [ updatedAttachment ] ) => {
1236+ if ( isBlobURL ( updatedAttachment . url ) ) {
1237+ return ;
1238+ }
1239+ item . onChange ?.( [ updatedAttachment ] ) ;
12121240 } ,
1213- ] ,
1214- ] ;
1215-
1216- // Add transcoding if format conversion is configured.
1217- if ( thumbnailTranscodeOperation ) {
1218- scaledOperations . push ( thumbnailTranscodeOperation ) ;
1241+ batchId,
1242+ parentId : item . id ,
1243+ additionalData : {
1244+ post : attachment . id ,
1245+ image_size : 'scaled' ,
1246+ convert_format : false ,
1247+ } ,
1248+ operations : scaledOperations ,
1249+ } ) ;
12191250 }
1220-
1221- scaledOperations . push ( OperationType . Upload ) ;
1222-
1223- dispatch . addSideloadItem ( {
1224- file : sourceForScaled ,
1225- onChange : ( [ updatedAttachment ] ) => {
1226- if ( isBlobURL ( updatedAttachment . url ) ) {
1227- return ;
1228- }
1229- item . onChange ?.( [ updatedAttachment ] ) ;
1230- } ,
1231- batchId,
1232- parentId : item . id ,
1233- additionalData : {
1234- post : attachment . id ,
1235- image_size : 'scaled' ,
1236- convert_format : false ,
1237- } ,
1238- operations : scaledOperations ,
1239- } ) ;
12401251 }
12411252 }
12421253
0 commit comments