Did I find the right examples for you? yes no

All Samples(73)  |  Call(73)  |  Derive(0)  |  Import(0)
Returns a sized and cropped version of the image, cropped to the
requested aspect ratio and size.

This function was contributed by Kevin Cazabon.

:param size: The requested output size in pixels, given as a
             (width, height) tuple.
:param method: What resampling method to use. Default is
               :py:attr:`PIL.Image.NEAREST`.
:param bleed: Remove a border around the outside of the image (from all(more...)

        def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)):
    """
    Returns a sized and cropped version of the image, cropped to the
    requested aspect ratio and size.

    This function was contributed by Kevin Cazabon.

    :param size: The requested output size in pixels, given as a
                 (width, height) tuple.
    :param method: What resampling method to use. Default is
                   :py:attr:`PIL.Image.NEAREST`.
    :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).
    :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).
    :return: An image.
    """

    # by Kevin Cazabon, Feb 17/2000
    # kevin@cazabon.com
    # http://www.cazabon.com

    # ensure inputs are valid
    if not isinstance(centering, list):
        centering = [centering[0], centering[1]]

    if centering[0] > 1.0 or centering[0] < 0.0:
        centering [0] = 0.50
    if centering[1] > 1.0 or centering[1] < 0.0:
        centering[1] = 0.50

    if bleed > 0.49999 or bleed < 0.0:
        bleed = 0.0

    # calculate the area to use for resizing and cropping, subtracting
    # the 'bleed' around the edges

    # number of pixels to trim off on Top and Bottom, Left and Right
    bleedPixels = (
        int((float(bleed) * float(image.size[0])) + 0.5),
        int((float(bleed) * float(image.size[1])) + 0.5)
        )

    liveArea = (0, 0, image.size[0], image.size[1])
    if bleed > 0.0:
        liveArea = (
            bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0] - 1,
            image.size[1] - bleedPixels[1] - 1
            )

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

    # calculate the aspect ratio of the liveArea
    liveAreaAspectRatio = float(liveSize[0])/float(liveSize[1])

    # calculate the aspect ratio of the output image
    aspectRatio = float(size[0]) / float(size[1])

    # figure out if the sides or top/bottom will be cropped off
    if liveAreaAspectRatio >= aspectRatio:
        # liveArea is wider than what's needed, crop the sides
        cropWidth = int((aspectRatio * float(liveSize[1])) + 0.5)
        cropHeight = liveSize[1]
    else:
        # liveArea is taller than what's needed, crop the top and bottom
        cropWidth = liveSize[0]
        cropHeight = int((float(liveSize[0])/aspectRatio) + 0.5)

    # 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

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

    # resize the image and return it
    return out.resize(size, method)
        


src/d/j/django-versatileimagefield-HEAD/versatileimagefield/versatileimagefield.py   django-versatileimagefield(Download)
        palette = image.getpalette()
        fit_image = ImageOps.fit(
            image=image,
            size=(width, height),
            method=Image.ANTIALIAS,

src/k/c/kcc-HEAD/kcc/image.py   kcc(Download)
            # Border can't be float so sometimes image might be 1px too small/large
            if self.image.size[0] != size[0] or self.image.size[1] != size[1]:
                self.image = ImageOps.fit(self.image, size, method=Image.BICUBIC, centering=(0.5, 0.5))
            return self.image
        # Otherwise - Upscale/Downscale
        else:
            method = Image.ANTIALIAS
        self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
        return self.image
 

src/p/y/python-placeholder-0.2/placeholder/placeholder.py   python-placeholder(Download)
                     fill=self.fg_color)
 
        txt_img = ImageOps.fit(text_img, self.size, method=Image.BICUBIC, centering=(0.5, 0.5))
 
        result_img.paste(txt_img)

src/d/j/django-tint-0.1/tint/imageprocs/default.py   django-tint(Download)
        else:
            raise Exception('Invalid valign')
        return ImageOps.fit(image, (params['width'], params['height']), Image.ANTIALIAS, 0, num_align)
 
    def grayscale(self, image, params):

src/d/j/django-tint-HEAD/tint/imageprocs/default.py   django-tint(Download)
        else:
            raise Exception('Invalid valign')
        return ImageOps.fit(image, (params['width'], params['height']), Image.ANTIALIAS, 0, num_align)
 
    def grayscale(self, image, params):

src/p/i/pilhelp-1.0/pilhelp/thumbnails.py   pilhelp(Download)
            img = bg
    else:
        img = ImageOps.fit(img, (width, height, ), method=method)
 
    return img

src/d/i/dimagi-utils-1.1.0/dimagi/utils/django/cached_object.py   dimagi-utils(Download)
                source_image_obj = self.fetch_image(source_key)
 
                target_image_obj = ImageOps.fit(source_image_obj, target_size, method=Image.BICUBIC)
                mime_ext = CachedImageMeta.get_extension(source_meta.content_type)
 

src/w/a/wazapp-HEAD/src/client/waimageprocessor.py   wazapp(Download)
 
			mask = mask.filter(ImageFilter.SMOOTH)
			croppedImage = ImageOps.fit(source, mask.size, method=Image.ANTIALIAS)
			croppedImage = croppedImage.convert("RGBA")
 

src/d/j/django-stdimage-0.5.10/stdimage/fields.py   django-stdimage(Download)
 
            if variation['crop']:
                img = ImageOps.fit(img, (variation['width'], variation['height']), method=resample)
            else:
                img.thumbnail((variation['width'], variation['height']), resample=resample)

src/p/l/plaquereader-HEAD/transcribe_plaques.py   plaquereader(Download)
    draw.ellipse((0, 0) + size, fill=0)
    # fit the mask over the original image
    output = ImageOps.fit(im, mask.size, centering=(0.5, 0.5))
    # paste mask over image, black border (outside of circle) is pasted 
    # over the original image but white centre (inside circle) is unchanged

  1 | 2 | 3 | 4 | 5 | 6  Next