so, I think the algorithm is not ideal here. I understand it's because we don't know the actual dimensions. I wonder if that's good enough for us here and now. My fear is that we could have a very compressed file that is actually very big, and this would fail here, because we'd have a small ratio whereas we should have a big one.

The code from David Flanagan is quite big for what we need in Messages. about 17ko minified. Jeff Muizelaar pointed me to https://web.archive.org/web/20130305080105/http://www.64lines.com/jpeg-width-height (this is a C implementation) that we might try to adapt for our use. Maybe also reuse some code from David.

I would agree doing this in a follow-up if this proves to be too much work, as what we have here is already better than what we had. Your call.