just change the $post->ID with get_post_thumbnail_id(), and possibly we can delete also the global $post;
if( ! ( function_exists( 'add_alt_image_content' ) ) ) {
function add_alt_image_content( $content ) {
if ( is_single() && in_the_loop() && is_main_query() ) {
global $post;
$image = get_post(get_post_thumbnail_id());
$image_title = $image->post_title;
$pattern = '~(<img.*? alt=")("[^>]*>)~i';
$replace="$1".$image_title.'$2';
$content = preg_replace( $pattern, $replace, $content );
return $content;
}
}
}
add_filter( 'the_content', 'add_alt_image_content' );