Welcome to the world of canvas manipulation :)
This is basically the core of how CamanJS works. Feel free to browse the source if you need any help or want to learn more! I haven't worked on it in awhile, but hope to get back to it some day.
Awesome! I was looking for this for a while before making my own, wish I came across it.