本文整理汇总了Python中pilkit.lib.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pilkit.lib.Image
的用法示例。
在下文中一共展示了Image.open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import open [as 别名]
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
示例2: test_make_gifs_opaque
# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import open [as 别名]
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)
示例3: create_image
# 需要导入模块: from pilkit.lib import Image [as 别名]
# 或者: from pilkit.lib.Image import open [as 别名]
def create_image():
return Image.open(get_image_file())