You can use has_post_format
to check the if the post format equal to some format type.
From the docs
if ( has_post_format('gallery') ) {
// Do something
}
Or use $format = get_post_format()
and then do some condition..
$format = get_post_format();
if ( $format == 'gallery' ) {
// Do something
}
If you want to use it outside the loop there is a problem with this method. because it check if the first post is in the format.
So its could return false positive if you are in category page when the first post has the post format too.
For outside the loop you can check for the get_queried_object
$queried_object = get_queried_object();
if($queried_object->taxonomy == 'post_format' && $queried_object->name == 'Gallery') {
// Do something
}