matthewwithanm / pilkit

Utilities and processors built for, and on top of PIL
BSD 3-Clause "New" or "Revised" License
196 stars 54 forks source link

ResizeToCover rounding error #1

Closed AlexNigl closed 11 years ago

AlexNigl commented 11 years ago

The process function in ResizeToCover calculates wrong.

Example: original size: 95x95 target size: 28x28 result: 27x27

The Problem is the float 2 int cast in line 48 and 49 in pilkit/processors/resize.py.

new_width, new_height = (int(original_width * ratio),
  int(original_height * ratio))

I recommend a round() before the cast.

new_width, new_height = (int(round(original_width * ratio)),
  int(round(original_height * ratio)))

That bug might be in other processors too.

matthewwithanm commented 11 years ago

@AlexNigl FYI I have seen this, I'm just out of town, and I want to make sure that I find all occurrences and take some time to write a test for it. Thanks for reporting!

matthewwithanm commented 11 years ago

@AlexNigl Thanks!