Get a file extension from a image URL?

I get a random image like this:

https://picsum.photos/200/200?random=61081

How can I get the image extension? jpg/png etc.?

I’ve considered this: $extension = pathinfo($file, PATHINFO_EXTENSION); but it does not work.

EDIT: $extension = pathinfo($file, PATHINFO_EXTENSION); gives an empty string.