here is my additional commit on top of yours: https://github.com/julienw/gaia/commit/06b9ed99fd008ae0b30df78a03312e9ad4dda3d9

I've made a pull request with both your and my commit here: https://github.com/mozilla-b2g/gaia/pull/18688

I didn't handle the previous comments I made, and I didn't fix the tests, and I didn't even tested the code. I only wanted to show you what was in my mind, because it's easier than using words :)

I kept the following:
* force a ratio of at least 2 if we need to resize
* use mozsamplesize if ratio is <= 8

here are the differences:
* I checked in firefox that currently the max mozsamplesize is 8; since we need to know the actual used samplesize, I used a switch/case to fix the samplesize. It would be better to know the actual value that Gecko used or the real image size. Maybe we can revisit once we do the jpeg reader.
* I directly use mozsamplesize from the ratio. If the ratio is > 8, I still use a samplesize = 8
* I force an integer ratio
* I do some basic checks at the start of resizeImageBlobWithRatio because after all it's a public method. We could want to move it to a closure instead and remove the basic checks
* Also in your patch, if mozSampleSize didn't work, we were starting again with ratio = 2, which was likely useless. My change fixes this too.

The main idea is: the ratio is what should control mozSamplesize, and we don't need 2 options.

Tell me what you think !