There were a few issues. You were using the viewport size in your distance function, but you needed to use the object size (i.e. the image size). Also, the functions in my comment you linked use radians, not degrees!
I updated the comment to show a live codepen example.
Additionally, here’s your codesandbox updated and simplified with the corrections (try both “contains” and “cover” modes):