本文整理汇总了Python中willow.plugins.pillow.PillowImage类的典型用法代码示例。如果您正苦于以下问题:Python PillowImage类的具体用法?Python PillowImage怎么用?Python PillowImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PillowImage类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
with open('tests/images/people.jpg', 'rb') as f:
# Open the image via Pillow
pillow_image = PillowImage.open(JPEGImageFile(f))
buffer_rgb = pillow_image.to_buffer_rgb()
colour_image = OpenCVColorImage.from_buffer_rgb(buffer_rgb)
self.image = OpenCVGrayscaleImage.from_color(colour_image)
示例2: test_jpeg_with_orientation_8
def test_jpeg_with_orientation_8(self):
with open('tests/images/orientation/landscape_8.jpg', 'rb') as f:
image = PillowImage.open(JPEGImageFile(f))
image = image.auto_orient()
self.assert_orientation_landscape_image_is_correct(image)
示例3: test_resize_animated_gif
def test_resize_animated_gif(self):
with open('tests/images/newtons_cradle.gif', 'rb') as f:
image = PillowImage.open(GIFImageFile(f))
resized_image = image.resize((100, 75))
self.assertFalse(resized_image.has_alpha())
self.assertTrue(resized_image.has_animation())
示例4: test_save_transparent_gif
def test_save_transparent_gif(self):
with open('tests/images/transparent.gif', 'rb') as f:
image = PillowImage.open(GIFImageFile(f))
# Save it into memory
f = io.BytesIO()
image.save_as_gif(f)
# Reload it
f.seek(0)
image = PillowImage.open(GIFImageFile(f))
self.assertTrue(image.has_alpha())
self.assertFalse(image.has_animation())
# Check that the alpha of pixel 1,1 is 0
self.assertEqual(image.image.convert('RGBA').getpixel((1, 1))[3], 0)
示例5: test_transparent_gif
def test_transparent_gif(self):
with open('tests/images/transparent.gif', 'rb') as f:
image = PillowImage.open(GIFImageFile(f))
self.assertTrue(image.has_alpha())
self.assertFalse(image.has_animation())
# Check that the alpha of pixel 1,1 is 0
self.assertEqual(image.image.convert('RGBA').getpixel((1, 1))[3], 0)
示例6: test_save_as_gif_converts_back_to_supported_mode
def test_save_as_gif_converts_back_to_supported_mode(self):
output = io.BytesIO()
with open('tests/images/transparent.gif', 'rb') as f:
image = PillowImage.open(GIFImageFile(f))
image.image = image.image.convert('RGB')
image.save_as_gif(output)
output.seek(0)
image = _PIL_Image().open(output)
self.assertEqual(image.mode, 'P')
示例7: test_open_webp_w_alpha
def test_open_webp_w_alpha(self):
with open('tests/images/tux_w_alpha.webp', 'rb') as f:
image = PillowImage.open(WebPImageFile(f))
self.assertTrue(image.has_alpha())
self.assertFalse(image.has_animation())
示例8: setUp
def setUp(self):
with open('tests/images/transparent.png', 'rb') as f:
self.image = PillowImage.open(PNGImageFile(f))
示例9: TestPillowOperations
import unittest
import io
import imghdr
from PIL import Image as PILImage
from willow.image import JPEGImageFile, PNGImageFile, GIFImageFile, WebPImageFile
from willow.plugins.pillow import _PIL_Image, PillowImage, UnsupportedRotation
no_webp_support = not PillowImage.is_format_supported("WEBP")
class TestPillowOperations(unittest.TestCase):
def setUp(self):
with open('tests/images/transparent.png', 'rb') as f:
self.image = PillowImage.open(PNGImageFile(f))
def test_get_size(self):
width, height = self.image.get_size()
self.assertEqual(width, 200)
self.assertEqual(height, 150)
def test_resize(self):
resized_image = self.image.resize((100, 75))
self.assertEqual(resized_image.get_size(), (100, 75))
def test_crop(self):
cropped_image = self.image.crop((10, 10, 100, 100))
self.assertEqual(cropped_image.get_size(), (90, 90))