Dear friends,
I have a problem that I don't seem to be able to solve... so I ask for your help! It is basically a math problem, not so much a python, but possibly there is an easy python solution.

My problem is the following: I have to know the scale factor appplied to an image with PIL im.thumbnail.
Let's say that I have an image 4822 x 3643 pixel and I want to scale it to 800 x 600 (maximum values)

If I run the following

``````im1.thumbnail((800,600), Image.ANTIALIAS)
``````

I get an image with 794 x 600 pixel (which is OK, of course).

So the equations should be
4822:100=794:x
and
3643:100=600:y

I would expect that x and y are the same value (since I scale that image of ONE specific value, say 16%)... but this is not, because of the rounding for the pixel values.
Indeed
x = 16.4661965989216092907507258399
and
y = 16.469942355201756793851221520725

How can I get the same value for x and y... whatever the input image size is?

Thank you!
Gianluca

Computers are binary beasts. You will always have a small roundoff error with the way floating point values are represented in a binary world. In your case pixels are integers and your calculations give floats. You might want to play with Python's round() and int() functions.