You should you this plug in instead: Category Image
And don’t be shy learning and using printf, it’s worth.
printf( '<a class="%1$s" href="https://wordpress.stackexchange.com/questions/223745/%2$s"><img class="img-class" src="%4$s" <h3>%3$s</h3></a>',
sanitize_html_class( $class_name ),
get_tag_link( $tag->term_id ),
sprintf( __( '%s') , $tag->name ),
z_taxonomy_image_url($tag->term_id, 'thumbnail' )
);
A note fore easier debugging, you can use var_dump($tag)
inside the foreach loop to now exactly what $tag
object has.