tomaszsita / wp-manual-image-crop

Repository of WordPress image cropping plugin http://wordpress.org/plugins/manual-image-crop/
67 stars 40 forks source link

Stretched images due to failed aspect ratio calculation #22

Open davelondono opened 9 years ago

davelondono commented 9 years ago

Hi, so there's a problem which happens under some particular circumstances:

I have an unusual image size of 880x240 hard-crop (which i call Extra-Wide), which works fine for some images, but then others were not. I discovered that the images it was not working on were the ones that were under certain dimensions, the specific case: a 1127x750 photo. A extra-wide cropped image is being generated with the right dimensions (880x240) but the actual photo is weirdly stretched vertically.

After carefully looking, I noticed that the cropping tool was showing a slightly narrower (vertically) cropping box than on other images where it was working as expected. A closer inspection to the javascript generated had in its settings "aspectRatio: 4.6958333333333" when it should have been "aspectRatio: 3.6666666666667" as it did on other images.

This takes me to /lib/ManualImageCropEditorWindow.php, lines 114 to 122. Here the aspect ratio for the cropping box is being overwritten when its over a value from calculations made based on the minimum with and height of the previewer. The problem: it disregards the real aspect ratio for the cropping tool, and then the actual cropping process will have mismatched ratios (from the cropping tool and the actual one) resulting in a stretched image.

i have commented the above mentioned lines and this resolved the problem, however i do not know their original purpose, so worth having a look to fix it properly for the next release.

Thanks