SERVER_NAME corresponds with your server. In order to grab the server name that the image is hosted on can be done a couple different ways.
You can add a get string to the image call IE: img src="http://yousite.com/image.png?sitecode=32423" which is a reference in your database to the site you put the image on. This method would be the most reliable imo.
And/Or
You should also be able to use the $_SERVER['HTTP_REFERRER'] string to get the domain and the page it came from, and parse it with the parse_url function. I am not sure how reliable this method would be, but some testing may be beneficial for you to know how reliable it is.
Hope that helps.