If you dig into the function wp_img_tag_add_width_and_height_attr
, you see the line where it goes wrong:
$size_array[1] = (int) round( $size_array[1] * $style_width / $size_array[0] );
Before this there are two places to do something. The first is a filter to bypass generating any widths and heights, which you could use like this:
add_filter ('wp_img_tag_add_width_and_height_attr', 'wpse424749_no_height_width');
function wpse424749_no_height_width () {return false;}
However, this may not be what you want, if you just want to prevent svg
images from having dimensions. This can be done in the second place, which is these lines:
$size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
if ( $size_array ) { ... here comes the lines where the division by 0 might occur
If you make sure no image dimensions are returned from the wp_image_src_get_dimensions
whenever those dimensions are zero you will skip the lines where the division by zero happens. Like this:
add_filter ('wp_image_src_get_dimensions', 'wpse424749_skip_zero_width_height',10,4);
function wpse424749_skip_zero_width_height ($dimensions, $image_src, $image_meta, $attachment_id) {
if ($dimensions[0] == 0 || $dimensions[1] ==0 ) return false;
else return ($dimensions);
}