本文整理汇总了Python中Image.NEAREST属性的典型用法代码示例。如果您正苦于以下问题:Python Image.NEAREST属性的具体用法?Python Image.NEAREST怎么用?Python Image.NEAREST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Image
的用法示例。
在下文中一共展示了Image.NEAREST属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expand
# 需要导入模块: import Image [as 别名]
# 或者: from Image import NEAREST [as 别名]
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.
示例2: check_image_background
# 需要导入模块: import Image [as 别名]
# 或者: from Image import NEAREST [as 别名]
def check_image_background(image):
im = convert_to_bw(image)
im_smol = im.resize((int(x / 4) for x in im.size), Image.NEAREST)
pixels = im_smol.getdata()
black_threshold = 150 # Threshold doesn't really matter as the image is only 0 and 255
nblack = 0
n = len(pixels)
for pixel in pixels:
if pixel < black_threshold:
nblack += 1
if (nblack / float(n)) > 0.5:
image = invert_image(image) # Invert image if more than half of the bw image is considered black
return image
示例3: load_imgfile
# 需要导入模块: import Image [as 别名]
# 或者: from Image import NEAREST [as 别名]
def load_imgfile(self, filename):
self.currentName = filename
fullFilename = os.path.join(self.inDir, filename)
print "Loading " + fullFilename
img = Image.open(fullFilename)
self.imageOrig = img
self.imageOrigSize = (img.size[0], img.size[1])
print "Image is " + str(self.imageOrigSize[0]) + "x" + str(self.imageOrigSize[1])
basewidth = 512
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
if fast_preview:
#does NOT create a copy so self.imageOrig is the same as self.image
img.thumbnail((basewidth,hsize), Image.NEAREST)
else:
if antialiase_original_preview:
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
else:
img = img.copy()
img.thumbnail((basewidth,hsize), Image.NEAREST)
self.image = img
print "Resized preview"
#self.geometry("1024x"+str(hsize + 100))
self.configure(relief='flat', background='gray')
self.imagePhoto = ImageTk.PhotoImage(self.image)
self.imageLabel.configure(width=self.imagePhoto.width(), height=self.imagePhoto.height())
self.imageLabel.create_image(0, 0, anchor=NW, image=self.imagePhoto)
self.previewPhoto = ImageTk.PhotoImage(self.image)
self.previewLabel.configure(image=self.previewPhoto)
self.item = None
self.verti_aux_item = None
self.horiz_aux_item = None
self.on_aspect_changed(None, None, None) #update aspect ratio with new image size
#self.imageLabel.pack(side = "left", fill = "both", expand = "yes")
#self.previewLabel.pack(side = "left", fill = "both", expand = "yes")
#self.c.pack(side = "bottom", fill = "both", expand = "yes")
#self.c.xview_moveto(0)
#self.c.yview_moveto(0)
#self.c.config(scrollregion=self.c.bbox('all'))