当前位置: 首页>>代码示例>>Python>>正文


Python Image.eval方法代码示例

本文整理汇总了Python中PIL.Image.eval方法的典型用法代码示例。如果您正苦于以下问题:Python Image.eval方法的具体用法?Python Image.eval怎么用?Python Image.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PIL.Image的用法示例。


在下文中一共展示了Image.eval方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_webp_to_png

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import eval [as 别名]
def convert_webp_to_png(path):
    im = Image.open(path)
    im.load()
    alpha = im.split()[-1]
    im = im.convert("RGB").convert("P", palette=Image.ADAPTIVE, colors=255)
    mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
    im.paste(255, mask)
    new_path = path.replace(".webp", ".png")
    im.save(new_path, transparency=255)
    return new_path 
开发者ID:bobloy,项目名称:Fox-V3,代码行数:12,代码来源:qrinvite.py

示例2: convertImagesToPIL

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import eval [as 别名]
def convertImagesToPIL(self, images, dither, nq=0,images_info=None):
        """ convertImagesToPIL(images, nq=0)
        
        Convert images to Paletted PIL images, which can then be 
        written to a single animaged GIF.
        
        """
        
        # Convert to PIL images
        images2 = []
        for im in images:
            if isinstance(im, Image.Image):
                images2.append(im)
            elif np and isinstance(im, np.ndarray):
                if im.ndim==3 and im.shape[2]==3:
                    im = Image.fromarray(im,'RGB')
                elif im.ndim==3 and im.shape[2]==4:
                    # im = Image.fromarray(im[:,:,:3],'RGB')
                    self.transparency = True
                    im = Image.fromarray(im[:,:,:4],'RGBA')
                elif im.ndim==2:
                    im = Image.fromarray(im,'L')
                images2.append(im)
        
        # Convert to paletted PIL images
        images, images2 = images2, []
        if nq >= 1:
            # NeuQuant algorithm
            for im in images:
                im = im.convert("RGBA") # NQ assumes RGBA
                nqInstance = NeuQuant(im, int(nq)) # Learn colors from image
                if dither:
                    im = im.convert("RGB").quantize(palette=nqInstance.paletteImage(),colors=255)
                else:
                    im = nqInstance.quantize(im,colors=255)  # Use to quantize the image itself

                self.transparency = True # since NQ assumes transparency
                if self.transparency:
                    alpha = im.split()[3]
                    mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)
                    im.paste(255,mask=mask)
                images2.append(im)
        else:
            # Adaptive PIL algorithm
            AD = Image.ADAPTIVE
            # for index,im in enumerate(images):
            for i in range(len(images)):
                im = images[i].convert('RGB').convert('P', palette=AD, dither=dither,colors=255)
                if self.transparency:
                    alpha = images[i].split()[3]
                    mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)
                    im.paste(255,mask=mask)
                images2.append(im)
        
        # Done
        return images2 
开发者ID:JuanPotato,项目名称:Legofy,代码行数:58,代码来源:images2gif_py3.py

示例3: convertImagesToPIL

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import eval [as 别名]
def convertImagesToPIL(self, images, dither, nq=0, images_info=None):
		""" convertImagesToPIL(images, nq=0)
		
		Convert images to Paletted PIL images, which can then be
		written to a single animaged GIF.
		
		"""
		
		# Convert to PIL images
		images2 = []
		for im in images:
			if isinstance(im, Image.Image):
				images2.append(im)
			elif np and isinstance(im, np.ndarray):
				if im.ndim == 3 and im.shape[2] == 3:
					im = Image.fromarray(im, 'RGB')
				elif im.ndim == 3 and im.shape[2] == 4:
					# im = Image.fromarray(im[:,:,:3],'RGB')
					self.transparency = True
					im = Image.fromarray(im[:, :, :4], 'RGBA')
				elif im.ndim == 2:
					im = Image.fromarray(im, 'L')
				images2.append(im)
				
		# Convert to paletted PIL images
		images, images2 = images2, []
		if nq >= 1:
			# NeuQuant algorithm
			for im in images:
				im = im.convert("RGBA")  # NQ assumes RGBA
				nqInstance = NeuQuant(im, int(nq))  #  Learn colors from image
				if dither:
					im = im.convert("RGB").quantize(palette=nqInstance.paletteImage(), colors=255)
				else:
					im = nqInstance.quantize(im, colors=255)  # Use to quantize the image itself
					
				self.transparency = True  # since NQ assumes transparency
				if self.transparency:
					alpha = im.split()[3]
					mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
					im.paste(255, mask=mask)
				images2.append(im)
		else:
			# Adaptive PIL algorithm
			AD = Image.ADAPTIVE
			# for index,im in enumerate(images):
			for i in range(len(images)):
				im = images[i].convert('RGB').convert('P', palette=AD, dither=dither, colors=255)
				if self.transparency:
					alpha = images[i].split()[3]
					mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
					im.paste(255, mask=mask)
				images2.append(im)
				
		# Done
		return images2 
开发者ID:Tyulis,项目名称:3DSkit,代码行数:58,代码来源:image2gif.py


注:本文中的PIL.Image.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。