Simplified image saving code

Updated the image saving logic to use interface to reduce repitition of logic.

Started to add GIF support, but more logic is need for gifs than simple encoding