本文整理汇总了Python中wand.image.Image.flip方法的典型用法代码示例。如果您正苦于以下问题:Python Image.flip方法的具体用法?Python Image.flip怎么用?Python Image.flip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wand.image.Image
的用法示例。
在下文中一共展示了Image.flip方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reorient_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flip [as 别名]
def reorient_image(cls, contents):
try:
handler = ImageHandler(blob=contents)
except IOError:
return contents
orientation = handler.metadata.get('exif:Orientation')
if not orientation:
return contents
{
1: lambda: handler,
2: lambda: handler.flop(),
3: lambda: handler.rotate(180),
4: lambda: handler.flip(),
5: lambda: handler.flip().rotate(90),
6: lambda: handler.rotate(90),
7: lambda: handler.flop().rotate(90),
8: lambda: handler.rotate(270),
}[int(orientation)]()
return handler.make_blob()
示例2: autorotate_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flip [as 别名]
def autorotate_image(in_path, out_path):
try:
metadata = pyexiv2.ImageMetadata(in_path)
metadata.read()
orient = int(metadata['Exif.Image.Orientation'].value)
except:
logger.warn(
"Image {0} did not have any EXIF rotation, did not rotate."
.format(in_path))
return
img = Image(filename=in_path)
if orient == 1:
logger.info("Image {0} is already rotated.".format(in_path))
shutil.copyfile(in_path, out_path)
return
elif orient == 2:
img.flip()
elif orient == 3:
img.rotate(180)
elif orient == 4:
img.flop()
elif orient == 5:
img.rotate(90)
img.flip()
elif orient == 6:
img.rotate(90)
elif orient == 7:
img.rotate(270)
img.flip()
elif orient == 8:
img.rotate(270)
img.save(filename=out_path)
示例3: autorotate_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flip [as 别名]
def autorotate_image(in_path, out_path):
""" Rotate an image according to its EXIF orientation tag.
:param in_path: Path to image that should be rotated
:type in_path: unicode
:param out_path: Path where rotated image should be written to
:type out_path: unicode
"""
try:
metadata = pyexiv2.ImageMetadata(in_path)
metadata.read()
orient = int(metadata['Exif.Image.Orientation'].value)
except:
logger.warn(
"Image {0} did not have any EXIF rotation, did not rotate."
.format(in_path))
return
img = Image(filename=in_path)
if orient == 1:
logger.info("Image {0} is already rotated.".format(in_path))
shutil.copyfile(in_path, out_path)
return
elif orient == 2:
img.flip()
elif orient == 3:
img.rotate(180)
elif orient == 4:
img.flop()
elif orient == 5:
img.rotate(90)
img.flip()
elif orient == 6:
img.rotate(90)
elif orient == 7:
img.rotate(270)
img.flip()
elif orient == 8:
img.rotate(270)
img.save(filename=out_path)
示例4: process_upload
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flip [as 别名]
def process_upload(upload, collection='uploads', image_size=(1280, 720),
thumbnail=True):
"""Processes the uploaded images in the posts and also the users avatars.
This should be extensible in future to support the uploading of videos,
audio, etc...
:param _id: The ID for the post, user or anything you want as the filename
:type _id: str
:param upload: The uploaded Werkzeug FileStorage object
:type upload: ``Werkzeug.datastructures.FileStorage``
:param collection: The GridFS collection to upload the file too.
:type collection: str
:param image_size: The max height and width for the upload
:type image_size: Tuple length 2 of int
:param thumbnail: Is the image to have it's aspect ration kept?
:type thumbnail: bool
"""
try:
# StringIO to take the uploaded image to transport to GridFS
output = io.BytesIO()
# All images are passed through Wand and turned in to PNG files.
# Unless the image is a GIF and its format is kept
# Will change if they need thumbnailing or resizing.
img = Image(file=upload)
# If the input file if a GIF then we need to know
gif = True if img.format == 'GIF' else False
animated_gif = True if gif and len(img.sequence) > 1 else False
# Check the exif data.
# If there is an orientation then transform the image so that
# it is always looking up.
try:
exif_data = {
k[5:]: v
for k, v in img.metadata.items()
if k.startswith('exif:')
}
orientation = exif_data.get('Orientation')
orientation = int(orientation)
if orientation: # pragma: no branch
if orientation == 2:
img.flop()
elif orientation == 3:
img.rotate(180)
elif orientation == 4:
img.flip()
elif orientation == 5:
img.flip()
img.rotate(90)
elif orientation == 6:
img.rotate(90)
elif orientation == 7:
img.flip()
img.rotate(270)
elif orientation == 8:
img.rotate(270)
except (AttributeError, TypeError, AttributeError):
pass
if thumbnail:
# If the GIF was known to be animated then save the animated
# then cycle through the frames, transforming them and save the
# output
if animated_gif:
animated_image = Image()
for frame in img.sequence:
frame.transform(resize='{0}x{1}>'.format(*image_size))
# Directly append the frame to the output image
animated_image.sequence.append(frame)
animated_output = io.BytesIO()
animated_output.format = 'GIF'
animated_image.save(file=animated_output)
animated_output.seek(0)
img.transform(resize='{0}x{1}>'.format(*image_size))
else:
# Just sample the image to the correct size
img.sample(*image_size)
# Turn off animated GIF
animated_gif = False
img.format = 'PNG'
uuid = get_uuid()
filename = '{0}.{1}'.format(uuid, 'png')
# Return the file pointer to the start
img.save(file=output)
output.seek(0)
# Place file inside GridFS
m.save_file(filename, output, base=collection)
animated_filename = ''
#.........这里部分代码省略.........