@@ -82,12 +82,13 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
82
82
*/
83
83
$ filter = static function ( $ sizes , $ size ) use ( $ block ) {
84
84
85
+ $ block_name = $ block ->name ;
85
86
$ id = $ block ->attributes ['id ' ] ?? 0 ;
86
87
$ alignment = $ block ->attributes ['align ' ] ?? '' ;
87
88
$ width = $ block ->attributes ['width ' ] ?? '' ;
88
89
$ max_alignment = $ block ->context ['max_alignment ' ];
89
90
90
- $ better_sizes = auto_sizes_calculate_better_sizes ( (int ) $ id , (string ) $ size , (string ) $ alignment , (string ) $ width , (string ) $ max_alignment );
91
+ $ better_sizes = auto_sizes_calculate_better_sizes ( (string ) $ block_name , ( int ) $ id , (string ) $ size , (string ) $ alignment , (string ) $ width , (string ) $ max_alignment );
91
92
92
93
// If better sizes can't be calculated, use the default sizes.
93
94
return false !== $ better_sizes ? $ better_sizes : $ sizes ;
@@ -124,14 +125,15 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
124
125
*
125
126
* @since n.e.x.t
126
127
*
128
+ * @param string $block_name The block name.
127
129
* @param int $id The image id.
128
130
* @param string $size The image size data.
129
131
* @param string $align The image alignment.
130
132
* @param string $resize_width Resize image width.
131
133
* @param string $max_alignment The maximum usable layout alignment.
132
134
* @return string|false An improved sizes attribute or false if a better size cannot be calculated.
133
135
*/
134
- function auto_sizes_calculate_better_sizes ( int $ id , string $ size , string $ align , string $ resize_width , string $ max_alignment ) {
136
+ function auto_sizes_calculate_better_sizes ( string $ block_name , int $ id , string $ size , string $ align , string $ resize_width , string $ max_alignment ) {
135
137
// Without an image ID or a resize width, we cannot calculate a better size.
136
138
if ( ! (bool ) $ id && ! (bool ) $ resize_width ) {
137
139
return false ;
@@ -166,9 +168,9 @@ function auto_sizes_calculate_better_sizes( int $id, string $size, string $align
166
168
*/
167
169
$ constraints = array (
168
170
'full ' => 0 ,
169
- 'left ' => 1 ,
170
- 'right ' => 1 ,
171
- 'wide ' => 2 ,
171
+ 'wide ' => 1 ,
172
+ 'left ' => 2 ,
173
+ 'right ' => 2 ,
172
174
'default ' => 3 ,
173
175
'center ' => 3 ,
174
176
);
@@ -187,9 +189,14 @@ function auto_sizes_calculate_better_sizes( int $id, string $size, string $align
187
189
188
190
case 'left ' :
189
191
case 'right ' :
190
- // These alignment get constrained by the wide layout size but do not get stretched.
191
- $ alignment = auto_sizes_get_layout_width ( 'wide ' );
192
- $ layout_width = sprintf ( '%1$spx ' , min ( (int ) $ alignment , $ image_width ) );
192
+ /*
193
+ * Update width for cover block.
194
+ * See https://github.com/WordPress/gutenberg/blob/938720602082dc50a1746bd2e33faa3d3a6096d4/packages/block-library/src/cover/style.scss#L82-L87.
195
+ */
196
+ if ( 'core/cover ' === $ block_name ) {
197
+ $ image_width = $ image_width * 0.5 ;
198
+ }
199
+ $ layout_width = sprintf ( '%1$spx ' , $ image_width );
193
200
break ;
194
201
195
202
case 'center ' :
0 commit comments