Is it possible to add an image to static resources using apex code and metadata?

On a detail page I want to click a button that says upload image and store that Url in metadata Field and than pass it to Static resource rather than in attachments on the individual record.

Is the possible and if so do you have any sample code?