[Image-SIG] ImageOps.fit(): centering parameter (PIL 1.1.7)
Olaf Dietrich
olaf at dtrx.de
Fri Jul 30 09:42:47 CEST 2010
Does the centering parameter of ImageOps.fit() really
work as intended (i.e. as described in the documentation)?
# @param centering Control the cropping position. Use (0.5, 0.5) for
# center cropping (e.g. if cropping the width, take 50% off of the
# left side, and therefore 50% off the right side). (0.0, 0.0)
# will crop from the top left corner (i.e. if cropping the width,
# take all of the crop off of the right side, and if cropping the
# height, take all of it off the bottom). (1.0, 0.0) will crop
# from the bottom left corner, etc. (i.e. if cropping the width,
# take all of the crop off the left side, and if cropping the height
# take none from the top, and therefore all off the bottom).
The relevant code should be (from ImageOps.py):
bleedPixels = (
int((float(bleed) * float(image.size[0])) + 0.5),
int((float(bleed) * float(image.size[1])) + 0.5)
)
liveArea = (
bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0] - 1,
image.size[1] - bleedPixels[1] - 1
)
...
# make the crop
leftSide = int(liveArea[0] + (float(liveSize[0]-cropWidth) * centering[0]))
if leftSide < 0:
leftSide = 0
topSide = int(liveArea[1] + (float(liveSize[1]-cropHeight) * centering[1]))
if topSide < 0:
topSide = 0
So, liveArea[0] = bleedPixels[0] = bleed * image.size[0] should
describe the border that is cropped (by default from left _and_ right).
This works - independent from centering[0] - for the symmetric case.
But leftSide will only be equal to liveArea[0] if either centering[0]==0
(which is _not_ the default case) or if liveSize[0]-cropWidth==0, which
seems to be the case in all my examples.
But the latter means that changing centering[0] does not have
any effect on the cropped area (which is what I do indeed observe).
So I wonder if I do not understand the documentation correctly or
if the code does not really do what it should do ...
Following the description above, I would have expected something
along the lines:
# make the crop
leftSide = int(liveArea[0] * 2 * centering[0])
topSide = int(liveArea[1] * 2 * centering[1])
instead of the above ...?
Thanks for any hints
Olaf
More information about the Image-SIG
mailing list