Check if var is imageobject or contentobject

I have a snippet that creates a figure.
I will give a content field or a file to snippet and test, if I have to do toFile() in the snippet or not. How can I do this?

if ($yourVar instanceof \Kirby\Content\Field) {
  $yourVar = $yourVar->toFile();
}

could be one way.