To add image alt and title attributes to images, add the following to functions.php:
function add_image_title( $attr, $attachment= null ) {
    $img_title= trim( strip_tags( $attachment->post_title ) );
    $attr['title'] = $img_title;
    $attr['alt'] = $img_title;
    return$attr;
}
add_filter( 'wp_get_attachment_image_attributes','add_imgage_title', 10, 2 );
or replace $attr[‘title’] with:
$attr['title'] = the_title_attribute( 'echo=0' );