Limit the size of canvases to 5MP (iOS restriction)

This is an attempt to fix #2439 and maybe some other related issues.
It seems to work for me but more tests are definitely needed.