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


Python Image.composite方法代码示例

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


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

示例1: process

# 需要导入模块: from imagekit.lib import Image [as 别名]
# 或者: from imagekit.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:HengeSense,项目名称:django-imagekit,代码行数:36,代码来源:base.py

示例2: process

# 需要导入模块: from imagekit.lib import Image [as 别名]
# 或者: from imagekit.lib.Image import composite [as 别名]
    def process(cls, image, fmt, obj=None):
        """Adds a watermark to an image."""
        if image.mode != 'RGBA':
            image = image.convert('RGBA')

        pink = (255, 94, 200)
        white = (255, 255, 255)

        im_width, im_height = image.size
        copyright = "Copyright \xa9 by the Artist and Burning Man"
    
        overlay = Image.new('RGBA', image.size, (0,0,0,0))
        draw = ImageDraw.Draw(overlay)
        draw.rectangle((0, im_height - 20, im_width, im_height),
                       fill=(0,0,0,90))
        draw.text((10, im_height - 15), copyright, fill=(255,255,255,90))
        newimage = Image.new('RGB', (im_width, im_height + 50), white)
        draw2 = ImageDraw.Draw(newimage)
        draw2.text((10, im_height + 5),
                   "\xa9 All images are copyright in their respective year, by "
                   "both the ",
                   fill=pink)
        draw2.text((10, im_height + 15),
                   "photographer and Burning Man. For publication or other use ",
                   fill=pink)
        draw2.text((10, im_height + 25),
                   "requests, contact the photographer at the email provided and ",
                   fill=pink) 
        draw2.text((10, im_height + 35),
                   "[email protected] for written permission.", fill=pink)

        comp = Image.composite(overlay, image, overlay)
        newimage.paste(comp, (0,0))
        return newimage, fmt
开发者ID:vaughnkoch,项目名称:bm.gallery,代码行数:36,代码来源:watermark.py

示例3: process

# 需要导入模块: from imagekit.lib import Image [as 别名]
# 或者: from imagekit.lib.Image import composite [as 别名]
	def process(self, image):
		mask = Image.open(os.path.join(settings.STATIC_ROOT, 'img/avatar-mask.png'))
		
		layer = Image.new('RGBA', image.size)
		layer.paste(mask)

		newImage = Image.composite(layer, image, layer)
		return newImage
开发者ID:BrunoBernardino,项目名称:unity-django,代码行数:10,代码来源:models.py

示例4: process

# 需要导入模块: from imagekit.lib import Image [as 别名]
# 或者: from imagekit.lib.Image import composite [as 别名]
    def process(self, img):

        # get watermark
        wm = self._get_watermark()
        wm_size = wm.size

        # print('wm', wm)
        # print('wm.mode', wm.mode)

        # from PIL.PngImagePlugin import PngImageFile
        # from PIL.JpegImagePlugin import JpegImageFile

        if self.scale:
            if isinstance(self.scale, (int, float)) and self.scale != 1:
                # L&X
                # wm_size[0] *= self.scale
                # wm_size[1] *= self.scale
                wm_size = (wm_size[0] * self.scale, wm_size[1] * self.scale)
                wm = wm.scale(wm_size)
            elif self.scale == True:
                # from .resize import ResizeToFit
                from imagekit.processors import ResizeToFit
                wm = ResizeToFit(width=img.size[0], height=img.size[1],
                                 upscale=True).process(wm)
                wm_size = wm.size

        # prepare image for overlaying (ensure alpha channel)
        if img.mode != 'RGBA':
            img = img.convert('RGBA')

        # create a layer to place the watermark
        layer = Image.new('RGBA', img.size, (0, 0, 0, 0))
        coords = _process_coords(img.size, wm_size, self.position)

        print('L&X', 'wm', wm)
        print('L&X', 'wm.size', wm.size)
        print('L&X', 'coords', coords)
        coords = (int(coords[0]), int(coords[1]))

        if self.repeat:
            sx = coords[0] % wm_size[0] - wm_size[0]
            sy = coords[1] % wm_size[1] - wm_size[1]
            for x in range(sx, img.size[0], wm_size[0]):
                for y in range(sy, img.size[1], wm_size[1]):
                    layer.paste(wm, (x, y))
        else:
            layer.paste(wm, coords)

        if self.opacity < 1:
            alpha = layer.split()[3]
            alpha = ImageEnhance.Brightness(alpha).enhance(self.opacity)
            layer.putalpha(alpha)

        # merge watermark layer
        img = Image.composite(layer, img, layer)

        return img
开发者ID:liuxue0905,项目名称:GoldenTimes,代码行数:59,代码来源:watermark.py

示例5: process

# 需要导入模块: from imagekit.lib import Image [as 别名]
# 或者: from imagekit.lib.Image import composite [as 别名]
    def process(self, img):

        # get watermark
        wm = self._get_watermark()
        wm_size = wm.size

        if self.scale:
            if isinstance(self.scale, (int, float)) and self.scale != 1:
                wm_size[0] *= self.scale
                wm_size[1] *= self.scale
                wm = wm.scale(wm_size)
            elif self.scale == True:
                wm = ResizeToFit(width=img.size[0], height=img.size[1],
                    upscale=True).process(wm)
                wm_size = wm.size


        # prepare image for overlaying (ensure alpha channel)
        if img.mode != 'RGBA':
            img = img.convert('RGBA')

        # create a layer to place the watermark
        layer = Image.new('RGBA', img.size, (0,0,0,0))
        coords = _process_coords(img.size, wm_size, self.position)

        if self.repeat:
            sx = coords[0] % wm_size[0] - wm_size[0]
            sy = coords[1] % wm_size[1] - wm_size[1]
            for x in range(sx, img.size[0], wm_size[0]):
                for y in range(sy, img.size[1], wm_size[1]):
                    layer.paste(wm, (x,y))
        else:
            layer.paste(wm, coords)


        if self.opacity < 1:
            alpha = layer.split()[3]
            alpha = ImageEnhance.Brightness(alpha).enhance(self.opacity)
            layer.putalpha(alpha)

        # merge watermark layer
        img = Image.composite(layer, img, layer)

        return img
开发者ID:freeusername,项目名称:english-i,代码行数:46,代码来源:processors.py

示例6: add_watermark

# 需要导入模块: from imagekit.lib import Image [as 别名]
# 或者: from imagekit.lib.Image import composite [as 别名]
def add_watermark(image, footer=True, extended=True):
    if image.mode != 'RGBA':
            image = image.convert('RGBA')

    pink = (255, 94, 200)
    white = (255, 255, 255)

    im_width, im_height = image.size
    log.debug('size: %s', image.size)
    if im_height:
        fontsize = int(im_height/34)
    else:
        fontsize = int(im_width/34)

    if fontsize > 16:
        fontsize = 16

    log.debug('font size=%i', fontsize)
    ttf = os.path.join(settings.MEDIA_ROOT, 'fonts', 'Tahoma.ttf')
    font = ImageFont.truetype(ttf, fontsize)

    overlay = Image.new('RGBA', image.size, (0,0,0,0))
    if footer:
        copyright = "Copyright \xa9 by the Artist and Burning Man"

        draw = ImageDraw.Draw(overlay)
        draw.rectangle((0, im_height - fontsize - 6, im_width, im_height),
                       fill=(0,0,0,90))
        draw.text((10, im_height - fontsize - 4), copyright, fill=(255,255,255,90), font=font)


    if extended:
        newimage = Image.new('RGB', (im_width, im_height + 200), white)
        textheight = draw_word_wrap(newimage, EXTRA_COPY, 10, 5, max_width=im_width-10, fill=pink, font=font, height_only=True)
        h = im_height + textheight + 5
        log.debug('new height: %s, textheight=%s', h, textheight)
        newimage = Image.new('RGB', (im_width, h), white)
    else:
        newimage = Image.new('RGB', (im_width, im_height))

    if extended:
        #draw2 = ImageDraw.Draw(newimage)
        draw_word_wrap(newimage, EXTRA_COPY, 10, im_height + 5, max_width=im_width-10, fill=pink, font=font)

        # draw2.text((10, h),
        #            "\xa9 All images are copyright in their respective year, by "
        #            "both the ",
        #            fill=pink,
        #            font=font)
        # h += fontsize + 3
        # draw2.text((10, h),
        #            "photographer and Burning Man. For publication or other use ",
        #            fill=pink,
        #            font=font)
        # h += fontsize + 3
        # draw2.text((10, h),
        #            "requests, contact the photographer at the email provided and ",
        #            fill=pink,
        #            font=font)
        # h += fontsize + 3
        # draw2.text((10, h),
        #            "[email protected] for written permission.",
        #            fill=pink,
        #            font=font)

    comp = Image.composite(overlay, image, overlay)
    newimage.paste(comp, (0,0))
    return newimage
开发者ID:bkroeze,项目名称:bm.gallery,代码行数:70,代码来源:watermark.py


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