add img class to native wordpress galleries

try this.Passed $attachment->ID to get_post_meta to retrive alt tag of each image

add_filter('wp_get_attachment_link', 'galleryWIthClass');
function galleryWithClass($src) {
$args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => get_the_ID()
); 
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$html= str_replace('<img', '<img class="'. $alt.'" ', $src);
return $html;
}
}
}