First off, you'll will need a function that allows you to upload to those sites. Most sites have what they call "API" (Application Programming Interface) that allows you to upload images to their site and return an image link, linking to that image.
Once you have that, the rest is simple.