Python Image 模块,NEAREST 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用Image.NEAREST

项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def file_to_img(width, height, filename):
    # Do a check for file type
    im = Image.open(filename).convert('RGBA')
    im = im.resize((Settings.actualWidth, Settings.height), Image.NEAREST)
    return im


# Takes index as an input at returns all indices for the character that index contains
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def create_crt_overlay(self):
        crt_img = Image.new("RGB", (1, Settings.height*2), (0,0,0))
        # Create repeating data for crt overlay
        imgdata = ((200,200,200),(50,50,50))*Settings.height
        crt_img.putdata(imgdata)
        crt_img = crt_img.resize((Settings.width*2, Settings.height*2), Image.NEAREST)
        return crt_img

    # Returns the pixels visible at the current zoom level
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def preview_putimg(self, ui_img):
        self.unfilteredPreview = ui_img
        pil_img = ui_to_pil(ui_img)
        pil_img = pil_img.resize((Settings.width*2, Settings.height*2), Image.NEAREST)
        pil_img = pil_img.convert("RGB")
        pil_img = ImageChops.multiply(pil_img.filter(ImageFilter.SMOOTH), self.crt_overlay)
        pil_img = ImageChops.screen(pil_img.filter(ImageFilter.GaussianBlur(5)), pil_img)
        ui_img = pil_to_ui(pil_img)
        self.superview['preview'].image = ui_img
        return True
项目:slam-tutorial-code    作者:tuongngoc    | 项目源码 | 文件源码
def set_background(self, np_array, color = False):
        """Takes a (numpy) array and sets this as background."""
        if color:
            img = Image.fromarray(np.flipud(np.uint8(np_array)), mode="RGB")
        else:
            img = Image.fromarray(np_array)
        if self.background_image_id:
            self.world_canvas.delete(self.background_image_id)
        img = img.resize(self.extents, Image.NEAREST)
        self.background_image = ImageTk.PhotoImage(img)
        self.background_id = self.world_canvas.create_image(0, 0,
            image=self.background_image, anchor=NW, tag="background")
        # Make sure drawing order is correct.
        self.set_display_order()
项目:CNCGToolKit    作者:cineuse    | 项目源码 | 文件源码
def expand(image, border=0, fill=0):
    "Add border to image"
    left, top, right, bottom = _border(border)
    width = left + image.size[0] + right
    height = top + image.size[1] + bottom
    out = Image.new(image.mode, (width, height), _color(fill, image.mode))
    out.paste(image, (left, top))
    return out

##
# Returns a sized and cropped version of the image, cropped to the
# requested aspect ratio and size.
# <p>
# The <b>fit</b> 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 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.
项目:SLAM    作者:jfjensen    | 项目源码 | 文件源码
def set_background(self, np_array, color = False):
        """Takes a (numpy) array and sets this as background."""
        if color:
            img = Image.fromarray(np.flipud(np.uint8(np_array)), mode="RGB")
        else:
            img = Image.fromarray(np_array)
        if self.background_image_id:
            self.world_canvas.delete(self.background_image_id)
        img = img.resize(self.extents, Image.NEAREST)
        self.background_image = ImageTk.PhotoImage(img)
        self.background_id = self.world_canvas.create_image(0, 0,
            image=self.background_image, anchor=NW, tag="background")
        # Make sure drawing order is correct.
        self.set_display_order()
项目:InstagramPosting    作者:LeviParadis    | 项目源码 | 文件源码
def expand(image, border=0, fill=0):
    "Add border to image"
    left, top, right, bottom = _border(border)
    width = left + image.size[0] + right
    height = top + image.size[1] + bottom
    out = Image.new(image.mode, (width, height), _color(fill, image.mode))
    out.paste(image, (left, top))
    return out

##
# Returns a sized and cropped version of the image, cropped to the
# requested aspect ratio and size.
# <p>
# The <b>fit</b> 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 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.
项目:ngx_status    作者:YoYoAdorkable    | 项目源码 | 文件源码
def expand(image, border=0, fill=0):
    "Add border to image"
    left, top, right, bottom = _border(border)
    width = left + image.size[0] + right
    height = top + image.size[1] + bottom
    out = Image.new(image.mode, (width, height), _color(fill, image.mode))
    out.paste(image, (left, top))
    return out

##
# Returns a sized and cropped version of the image, cropped to the
# requested aspect ratio and size.
# <p>
# The <b>fit</b> 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 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.