How to get a media image value from taxonomy term in drupal 10

Include the Taxonomy class

use Drupal\taxonomy\Entity\Term;

$term = Drupal::routeMatch()->getParameter('taxonomy_term');

if (!$term instanceof Term) { 

  return; 

}

// Get the taxonomy term object. 

$taxonomy = $term->getTerm();

$image = $term->get('field_image')->entity->field_media_image->entity->getFileUri();

Category