@@ -201,7 +201,10 @@ function auto_sizes_calculate_better_sizes( int $id, $size, string $align, int $
201
201
case 'wide ' :
202
202
$ layout_width = auto_sizes_get_layout_width ( 'wide ' );
203
203
if ( str_ends_with ( $ layout_width , 'px ' ) ) {
204
- $ layout_width = (int ) $ layout_width * $ container_relative_width ;
204
+ // First remove 'px' from width.
205
+ $ layout_width = str_replace ( 'px ' , '' , $ layout_width );
206
+ // Convert to float for better precision.
207
+ $ layout_width = (float ) $ layout_width * $ container_relative_width ;
205
208
$ layout_width = sprintf ( '%dpx ' , (int ) $ layout_width );
206
209
}
207
210
break ;
@@ -218,7 +221,10 @@ function auto_sizes_calculate_better_sizes( int $id, $size, string $align, int $
218
221
* on the server. Otherwise, we need to rely on CSS functions.
219
222
*/
220
223
if ( str_ends_with ( $ layout_width , 'px ' ) ) {
221
- $ layout_width = (int ) $ layout_width * $ container_relative_width ;
224
+ // First remove 'px' from width.
225
+ $ layout_width = str_replace ( 'px ' , '' , $ layout_width );
226
+ // Convert to float for better precision.
227
+ $ layout_width = (float ) $ layout_width * $ container_relative_width ;
222
228
$ layout_width = sprintf ( '%dpx ' , min ( (int ) $ layout_width , $ image_width ) );
223
229
} else {
224
230
$ layout_width = sprintf ( 'min(%1$s, %2$spx) ' , $ layout_width , $ image_width );
0 commit comments