Customise the WordPress gallery html layout

I find a solution for this:

// Customise the WordPress gallery html layout
add_filter('post_gallery','customFormatGallery',10,2);
function customFormatGallery($string,$attr){
    $output = "<div class=\"mihan-gallery\">";
    $posts = get_posts(array('include' => $attr['ids'],'post_type' => 'attachment'));
    foreach($posts as $imagePost){
        $output .= "<a class=\"mihangitem\" href="https://wordpress.stackexchange.com/questions/384853/".wp_get_attachment_image_src($imagePost->ID,"mihan-large')[0]."'><img src="https://wordpress.stackexchange.com/questions/384853/".wp_get_attachment_image_src($imagePost->ID,"mihan-medium')[0]."'></a>";
    }
    $output .= "<div class=\"clear\"></div></div>";
    return $output;
}