ImageOps.fit(): cropping area wrong (too small by 1 px) (PIL 1.1.7)

Olaf Dietrich <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
Apparently, the cropping area is miscalculated in the
ImageOps.fit() function in PIL 1.1.7:

Calling fit() with bleed=0.0 should return an image without
any removed border:

# @param bleed Remove a border around the outside of the image (from all
#     four edges.  The value is a decimal percentage (use 0.01 for one
#     percent).  The default value is 0 (no border).

However, the returned image after the internal call of crop,
i.e. after the lines

    out = image.crop(
        (leftSide, topSide, leftSide + cropWidth, topSide + cropHeight)
        )

is in fact cropped: 1 column/row of pixels is removed at the
right hand side and at the bottom, i.e. if we start with
a 100×100 pixel image and call ImageOps.fit() without
the bleed and centering parameters (or with bleed=0.0):

	print "before image.crop:", image.size
    out = image.crop(
        (leftSide, topSide, leftSide + cropWidth, topSide + cropHeight)
        )
	print "after image.crop:", out.size

this results in:

| before image.crop: (100, 100)
| after image.crop: (99, 99)


If I assume that the convention in ImageOps.crop() is correct,
i.e.

    left, top, right, bottom = _border(border)
    return image.crop(
        (left, top, image.size[0]-right, image.size[1]-bottom)
        )

then crop should be called with the arguments "0 0 size[0] size[1]"
if NO cropping is intended. This means that EITHER already the
definition of liveArea (in ImageOps.fit()) should be changed from:

    liveArea = (
        bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0] - 1,
        image.size[1] - bleedPixels[1] - 1
        )
to
    liveArea = (
        bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0],
        image.size[1] - bleedPixels[1]
        )

OR the definition of liveSize should be change from

    liveSize = (liveArea[2] - liveArea[0], liveArea[3] - liveArea[1])
to
    liveSize = (liveArea[2] - liveArea[0] + 1, liveArea[3] - liveArea[1] + 1)

OR cropWidth and cropHeight should be defined as

        cropHeight = liveSize[1] + 1
        cropWidth = liveSize[0] + 1



This problem is independent of the one concerning the
centering parameter that I described in my message from 30 July.


Best regards
Olaf
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.