to get the location of the website, you write the following in js
window.location.href //gives complete href path
to add it to an image, you can append an image to the html by writing:
var elem = document.createElement("img");
elem.src = window.location.href+"/my-image.png";
elem.setAttribute("height", "200");
elem.setAttribute("width", "200");
elem.setAttribute("alt", "my image");
document.querySelector("#image-container").appendChild(elem);
Updated answer no.2:
Since it is your base path that you want, you can hardcode it since its never changing.
Append an image to the html by writing:
var fullPath = window.location.href;
var baseDomain = fullPath.split('site1')[0];
var pngPath = '_catalogs/masterpage/images/banner1.png';
var elem = document.createElement("img");
elem.src = baseDomain + pngPath;
elem.setAttribute("height", "200");
elem.setAttribute("width", "200");
elem.setAttribute("alt", "Banner");
document.querySelector("#banner").appendChild(elem);