esimov / caire

Content aware image resize library
MIT License
10.36k stars 384 forks source link

Improved scaling #60

Closed micahcantor closed 4 years ago

micahcantor commented 4 years ago

This change targets the scaling done before seam carving the image. The new scaling works by:

  1. Finding the scale factor (input length / target length) for each side.
  2. Dividing the input side lengths by the smaller of these two factors to get the side lengths after scaling.
  3. Calculating the remaining pixels needed to be removed by carving by subtracting the target length from scale length.

What this will do is scale one side directly to the target length, and the other proportionally larger than the target length. As an example, if an input of 5000x2500 has a target resize of 1920x1080, it is first scaled to 2160x1080. The amount of pixels needed to be removed by carving is then 240x0.

esimov commented 4 years ago

@micahcantor it looks good to me. I've already merged it back to the master branch. Thank you for the contribution!