To view an image that someone gave me permission to view:
I would verify that the image is the owners image, next ensure the id of guest viewer is in the related table of allowed to view (just example). For this I wouldn't try to setup all those permissions, I would just setup some if statements as needed.
pseudocode
if user 127 is allowed to view my images then show the image
And setup a redirect or whatever if not allowed. Just a way I'd do it, so suggestion only.