Security checks on uploads

We were already checking the dimensions of the uploaded images but the code wasn’t working. Improved it and added a test to make sure it doesn’t regress

https://github.com/discourse/discourse/commit/a9099f9e2383affcdca60e86ab167216f1ec68b2