How to style image url in Drupal 8.

Get uri from image file and style it.
<?php
use Drupal\image\Entity\ImageStyle;
use
Drupal\file\Entity\File;

$file = File::load($fid);
$uri = $file->getFileUri();
$url = ImageStyle::load('thumbnail')->buildUrl($uri);
?>