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


Python lib.Image类代码示例

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


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

示例1: process

 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,代码行数:34,代码来源:base.py

示例2: test_resize_antialiasing

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,代码行数:28,代码来源:test_processors.py

示例3: test_format_normalization

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,代码行数:7,代码来源:test_utils.py

示例4: test_coloroverlay

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,代码行数:8,代码来源:test_processors.py

示例5: test_convert

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,代码行数:8,代码来源:test_processors.py

示例6: test_resize_rounding

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,代码行数:8,代码来源:test_processors.py

示例7: test_resizetofit

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,代码行数:9,代码来源:test_processors.py

示例8: test_upscale

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,代码行数:14,代码来源:test_processors.py

示例9: process

def process(image_url,  processor = None, width=None, height=None, resolution=None, quality=100):
    conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
    bucket = conn.get_bucket(settings.AWS_STORAGE_BUCKET_NAME) 
    if image_url[0] =='/': image_url = image_url[1:] 
    r = requests.get(image_url.replace('https', 'http'))
    img = Image.open(StringIO(r.content))
    processor = ResizeToFit(width, height)
    new_img = processor.process(img)
    new_file = StringIO()
    save_image(new_img, new_file, 'JPEG')
    new_k = Key(bucket)
    parts = urlparse(image_url)
    img_name = os.path.splitext(os.path.basename(parts.path))[0]
    new_k.key = 'il/{}x{}/{}.jpeg'.format(width, height, img_name)
    new_k.content_type = 'image/jpeg'
    new_k.set_contents_from_file(new_file, policy='public-read')
    new_image_url = new_k.generate_url(0, query_auth=False, force_http=True)
    processed_image,_ = ProcessedImage.objects.update_or_create(source_image = image_url, processed_image = new_image_url)
    return processed_image
    
    
开发者ID:mykonosbiennale,项目名称:mykonosbiennale.github.io,代码行数:19,代码来源:processor.py

示例10: test_should_call_resizetofill_when_crop_and_ancho_is_passed

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,代码行数:4,代码来源:test_processors.py

示例11: test_resizetofit_mat

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,代码行数:4,代码来源:test_processors.py

示例12: test_make_gifs_opaque

def test_make_gifs_opaque():
    dir = os.path.dirname(__file__)
    path = os.path.join(dir, 'assets', 'cat.gif')
    gif = Image.open(path)
    MakeOpaque().process(gif)
开发者ID:matthewwithanm,项目名称:pilkit,代码行数:5,代码来源:test_processors.py

示例13: process

 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,代码行数:6,代码来源:overlay.py

示例14: test_should_repass_upscale_option_false

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,代码行数:4,代码来源:test_processors.py

示例15: test_should_raise_exception_when_crop_is_passed_without_height_and_width

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,代码行数:6,代码来源:test_processors.py


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