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


Python Image.new方法代码示例

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


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

示例1: process

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [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: test_format_normalization

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_format_normalization():
    """
    Make sure formats are normalized by ``prepare_image()``.
    See https://github.com/matthewwithanm/django-imagekit/issues/262
    """
    im = Image.new('RGBA', (100, 100))
    ok_('transparency' in prepare_image(im, 'gIF')[1])
开发者ID:andreacimino,项目名称:pilkit,代码行数:9,代码来源:test_utils.py

示例3: test_resize_antialiasing

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_resize_antialiasing():
    """
    Test that the Resize processor antialiases.

    The Resize processor is used by all of the Resize* variants, so this should
    cover all of resize processors. Basically, this is to test that it converts
    to RGBA mode before resizing.

    Related: jdriscoll/django-imagekit#192

    """
    # Create a palette image and draw a circle into it.
    img = Image.new('P', (500, 500), 1)
    img.putpalette([
        0,   0,   0,
        255, 255, 255,
        0,   0,   255,
    ])
    d = ImageDraw.ImageDraw(img)
    d.ellipse((100, 100, 400, 400), fill=2)

    # Resize the image using the Resize processor
    img = Resize(100, 100).process(img)

    # Count the number of colors
    color_count = len(list(filter(None, img.histogram())))

    assert_true(color_count > 2)
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:30,代码来源:test_processors.py

示例4: test_convert

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_convert():
    img = Image.new('RGBA', (200, 100))

    img_RGBa = Convert("RGBa").process(img)
    eq_(img_RGBa.mode, "RGBa")

    img_RGBa_RGBA = Convert("RGBA").process(img)
    eq_(img_RGBa_RGBA.mode, "RGBA")
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:10,代码来源:test_processors.py

示例5: test_coloroverlay

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_coloroverlay():
    """
    Test that the ColorOverlay processor
    """
    img = Image.new('RGB', (200, 100))
    color = ImageColor.getrgb('#cc0000')
    img = ColorOverlay(color, overlay_opacity=1.0).process(img)
    eq_(img.getpixel((0,0)), (204, 0, 0))
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:10,代码来源:test_processors.py

示例6: test_resize_rounding

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_resize_rounding():
    """
    Regression test for matthewwithanm/pilkit#1
    """

    img = Image.new('RGB', (95, 95))
    img = ResizeToFill(28, 28).process(img)
    eq_(img.size, (28, 28))
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:10,代码来源:test_processors.py

示例7: test_resizetofit

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_resizetofit():
    # First create an image with aspect ratio 2:1...
    img = Image.new('RGB', (200, 100))

    # ...then resize it to fit within a 100x100 canvas.
    img = ResizeToFit(100, 100).process(img)

    # Assert that the image has maintained the aspect ratio.
    eq_(img.size, (100, 50))
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:11,代码来源:test_processors.py

示例8: test_upscale

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_upscale():
    """
    Test that the upscale argument works as expected.

    """

    img = Image.new('RGB', (100, 100))

    for P in [Resize, ResizeToFit, ResizeToFill, SmartResize]:
        img2 = P(500, 500, upscale=True).process(img)
        eq_(img2.size, (500, 500))

        img2 = P(500, 500, upscale=False).process(img)
        eq_(img2.size, (100, 100))
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:16,代码来源:test_processors.py

示例9: test_resizetofit_mat

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_resizetofit_mat():
    img = Image.new('RGB', (200, 100))
    img = ResizeToFit(100, 100, mat_color=0x000000).process(img)
    eq_(img.size, (100, 100))
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:6,代码来源:test_processors.py

示例10: test_should_call_resizetofit_when_crop_is_not_passed

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_should_call_resizetofit_when_crop_is_not_passed(my_mock):
    img = Image.new('RGB', (100, 100))
    Thumbnail(height=200, width=200, crop=False).process(img)
    assert_true(my_mock.called)
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:6,代码来源:test_processors.py

示例11: test_should_call_resizetofill_when_crop_and_ancho_is_passed

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_should_call_resizetofill_when_crop_and_ancho_is_passed(my_mock):
    img = Image.new('RGB', (100, 100))
    Thumbnail(height=200, width=200, anchor='fake').process(img)
    assert_true(my_mock.called)
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:6,代码来源:test_processors.py

示例12: test_should_repass_upscale_option_false

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_should_repass_upscale_option_false(my_mock):
    img = Image.new('RGB', (100, 100))
    Thumbnail(height=200, width=200, upscale=False).process(img)
    my_mock.assert_called_once_with(width=200, upscale=False, height=200)
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:6,代码来源:test_processors.py

示例13: test_should_raise_exception_when_crop_is_passed_without_height_and_width

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [as 别名]
def test_should_raise_exception_when_crop_is_passed_without_height_and_width():
    img = Image.new('RGB', (100, 100))
    try:
        Thumbnail(crop=True).process(img)
    except Exception as e:
        eq_(str(e), 'You must provide both a width and height when cropping.')
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:8,代码来源:test_processors.py

示例14: process

# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import new [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.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。