First you have to load your file. In Drupal 8 everything is based on entities, and so are files. Loading a file is the same as loading a node.
$file = File::load($fid);
If your file is valid, you can start by building the render array for the image.
In the showed example, "thumbnail" is the used image style.
$variables = array(
'style_name' => 'thumbnail',
'uri' => $file->getFileUri(),
);
// The image.factory service will check if our image is valid.
$image = \Drupal::service('image.factory')->get($file->getFileUri());
if ($image->isValid()) {
$variables['width'] = $image->getWidth();
$variables['height'] = $image->getHeight();
}
else {
$variables['width'] = $variables['height'] = NULL;
}
$logo_render_array = [
'#theme' => 'image_style',
'#width' => $variables['width'],
'#height' => $variables['height'],
'#style_name' => $variables['style_name'],
'#uri' => $variables['uri'],
];