if ($message_owner->user_picture && !$message_owner->user_picture->isEmpty()) {
$render_array = [
'#theme' => 'image_style',
'#style_name' => 'privatemsg_avatar',
'#uri' => $message_owner->user_picture->entity->getFileUri(),
'#alt' => $message_owner->getDisplayName(),
];
$rendered_image = \Drupal::service('renderer')->render($render_array);
}