當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。