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


Python Image.composite方法代码示例

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


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

示例1: process

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import composite [as 别名]
 def process(self, img):
     # Convert bgcolor string to RGB value.
     background_color = ImageColor.getrgb(self.background_color)
     # Handle palleted images.
     img = img.convert('RGBA')
     # Copy orignial image and flip the orientation.
     reflection = img.copy().transpose(Image.FLIP_TOP_BOTTOM)
     # Create a new image filled with the bgcolor the same size.
     background = Image.new("RGBA", img.size, background_color)
     # Calculate our alpha mask.
     start = int(255 - (255 * self.opacity))  # The start of our gradient.
     steps = int(255 * self.size)  # The number of intermedite values.
     increment = (255 - start) / float(steps)
     mask = Image.new('L', (1, 255))
     for y in range(255):
         if y < steps:
             val = int(y * increment + start)
         else:
             val = 255
         mask.putpixel((0, y), val)
     alpha_mask = mask.resize(img.size)
     # Merge the reflection onto our background color using the alpha mask.
     reflection = Image.composite(background, reflection, alpha_mask)
     # Crop the reflection.
     reflection_height = int(img.size[1] * self.size)
     reflection = reflection.crop((0, 0, img.size[0], reflection_height))
     # Create new image sized to hold both the original image and
     # the reflection.
     composite = Image.new("RGBA", (img.size[0], img.size[1] + reflection_height), background_color)
     # Paste the orignal image and the reflection into the composite image.
     composite.paste(img, (0, 0))
     composite.paste(reflection, (0, img.size[1]))
     # Return the image complete with reflection effect.
     return composite
开发者ID:ChaseByInfinity,项目名称:creme,代码行数:36,代码来源:base.py

示例2: process

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import composite [as 别名]
 def process(self, img):
     original = img = img.convert('RGB')
     overlay = Image.new('RGB', original.size, self.color)
     mask = Image.new('RGBA', original.size, (0,0,0,int((1.0 - self.overlay_opacity)*255)))
     img = Image.composite(original, overlay, mask).convert('RGB')
     return img
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:8,代码来源:overlay.py


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