Hey sorry for the slow response.
That function doesn't need a particular location. It just needs to be available to the code that needs it. So it's up to you where to put it.
As I recall, that output from the function is the correct output. It encodes the image into text and tells the img tag to load it from there when you put it in its src tag.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.