Added function to scale images when downloading to resolve memory leak and memory overload issues