FIX: Perform crop using user-specified image sizes (PR #9224)

It used to resize the images to max width and height first and then perform the crop operation. This is wrong because it ignored the user specified image sizes from the Markdown.

GitHub

oops I think I asked @vinothkannans to look at something similar as well.

Since this is a very visual change @nbianca can you post some screenshots of before and after with markdown?

Before localhost_3000_t_test-image-crop_129_2

After localhost_3000_t_test-image-crop_129_2 (1)

Does this mean we now onebox every image in a post, regardless of size?

There is another check (line 325) which returns early if the image does not exceed maximum dimensions.

The code is looking ok, but I’m not sure exactly what the intention is here?

We had a feature which crops very tall images. Does this PR remove that feature?

The images are still cropped when necessary, but it gives user some control over image sizes.

As an example, I used the image from this topic and the following raw post:

A very tall image, unmodified (original size 1097x3351):

![image](upload://dBlV2poMFtso5zGLgXpcBraTVxg.png)

Very tall image, with a given size of 489x1500:

![image|489x1500](upload://dBlV2poMFtso5zGLgXpcBraTVxg.png) 

Very tall image, with a given size of 326x1000:

![image|326x1000](upload://dBlV2poMFtso5zGLgXpcBraTVxg.png) 

Very tall image, with a given size of 163x500:

![image|163x500](upload://dBlV2poMFtso5zGLgXpcBraTVxg.png)

There are two results (before and after this pull request):

before fixes

after fixes

Looks much better - thanks for all the screenshots :heart:

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/min-ratio-to-crop-site-setting-should-respect-w-h-ratio-as-defined-in-markdown/138374/23

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/image-resizing-doesnt-seem-to-be-working/145092/11