You have a page, (e.g. index.html).
When somebody arrives at that page and the query string ?ref=cookieval is present in the url, you want to set a cookie (e.g. imageSrc = cookieval).
Then, on that page and every subsequent page the user visits, you want to read the cookie value and replace an already existing image on the page, with one whose name is stored in the cookie (e.g. img src="myImage.png" should become img src="cookieval.png").