There are at least couple open source projects that handle dynamic image generation on the backend quite nicely. It seems photon is dead, but I found it works quite well and is easy to extend. Thumbor seems quite active although I've never used it myself.
https://github.com/thumbor/thumbor
https://github.com/1000Memories/photon-core