I suppose it would be nice to have unit tests for this. If they already exist, please move to apps/sharedtests.

Otherwise, feel free to write one and add it to this PR.  (I'm willing to land without it, though).  You can use the toBlob() function on a canvas to create jpeg and png blobs.  I don't know if that works for gifs, so you might need an actual gif file to test that case.