本文整理汇总了Python中wand.image.Image.flop方法的典型用法代码示例。如果您正苦于以下问题:Python Image.flop方法的具体用法?Python Image.flop怎么用?Python Image.flop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wand.image.Image
的用法示例。
在下文中一共展示了Image.flop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autorotate_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [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)
示例2: main
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [as 别名]
def main():
req_width = 595
req_height = 486
baby_img = Image(filename="baby_cc_sh.png")
baby_img = resize_to_height(baby_img, req_height)
baby_img.flop()
full_img = new_blank_png(req_width, req_height)
full_img.composite(baby_img, 0, 0)
display(full_img)
示例3: __init__
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [as 别名]
class Character:
def __init__(self, name, text):
self.avatar = None
self.name = name
self.text = [text]
self.x = 0
self.y = 0
def set_avatar(self, file):
self.avatar = file
self.img = Image(filename='/home/donginger/donginger/development/plugins/py_toon/characters/' + self.avatar)
def place(self):
self.img.x = self.x
self.img.y = self.y
def flip(self):
self.img.flop()
示例4: main
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [as 别名]
def main():
# Resize image to height (but do not change the aspect ratio)
#
req_width = 595
req_height = 486
baby_img = Image(filename="baby_cc_sh.png")
baby_img = resize_to_height(baby_img, req_height)
# For this particular image, reflect image along vertical
# axis to have face directed towards right of page.
#
baby_img.flop()
# Create the the gradient transition that will later be used
# in the opacity mask.
#
gradient_blob = create_gradient_blob(req_height, 75, gradient([
(1.0, (0x00, 0x00, 0x00), (0xFF, 0xFF, 0xFF)), # top
]))
gradient_img = Image(blob=gradient_blob)
gradient_img.rotate(90.0)
# When building the opacity mask, must start with an image
# having a solid colour (i.e., begin as a "matte" image).
# Without this, the later "composite_channel" operations
# will simply not work.
#
opacity_mask = new_blank_png(req_width, req_height, color=Color('white'))
white_field = new_blank_png(230, req_height, Color('white'))
black_field = new_blank_png(290, req_height, Color('black'))
opacity_mask.composite(white_field, 0, 0)
opacity_mask.composite(black_field, 230+75, 0)
opacity_mask.composite(gradient_img, 230, 0)
# Now take the resized baby image and have it fade to the right
# (in order to blend with later operations).
#
full_img = new_blank_png(req_width, req_height)
full_img.composite(baby_img, 0, 0)
full_img.composite_channel(channel='all_channels', image=opacity_mask, operator='copy_opacity')
示例5: reorient_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [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()
示例6: autorotate_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [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)
示例7: process_upload
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [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 = ''
#.........这里部分代码省略.........
示例8: slice02
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import flop [as 别名]
def slice02():
# Resize image to height (but do not change the aspect ratio)
#
req_width = 595
req_height = 486
baby_img = Image(filename=IMAGE_PATH + "baby_cc_sh.png")
baby_img = resize_to_height(baby_img, req_height)
# For this particular image, reflect image along vertical
# axis to have face directed towards right of page.
#
baby_img.flop()
# Create the the gradient transition that will later be used
# in the opacity mask.
#
gradient_blob = create_gradient_blob(req_height, 75, gradient([
(1.0, (0x00, 0x00, 0x00), (0xFF, 0xFF, 0xFF)), # top
]))
gradient_img = Image(blob=gradient_blob)
gradient_img.rotate(90.0)
# When building the opacity mask, must start with an image
# having a solid colour (i.e., begin as a "matte" image).
# Without this, the later "composite_channel" operations
# will simply not work.
#
opacity_mask = new_blank_png(req_width, req_height, color=Color('white'))
left_field = new_blank_png(230, req_height, Color('white'))
right_field = new_blank_png(290, req_height, Color('black'))
opacity_mask.composite(left_field, 0, 0)
opacity_mask.composite(right_field, 230+75, 0)
opacity_mask.composite(gradient_img, 230, 0)
# Now take the resized baby image and have it fade to the right
# (in order to blend with later operations).
#
face_img = new_blank_png(req_width, req_height)
face_img.composite(baby_img, 0, 0)
face_img.composite_channel(channel='all_channels', image=opacity_mask,
operator='copy_opacity')
# Bring in the illustrative image that will eventually be blended in
# with the child's face.
#
accent_img = Image(filename = IMAGE_PATH + "funky_illustration.png")
accent_img = resize_to_percent(accent_img, 60)
accent_img = resize_to_height(accent_img, 486)
cropped_img = accent_img.clone()
cropped_img.crop(top=0, left=275, width=340, height=486)
screen_img = new_blank_png(340, 486, color=Color('rgb(150,150,150)'))
cropped_img.composite_channel(channel='all_channels', image=screen_img,
operator='screen')
accent_img = new_blank_png(req_width, req_height)
accent_img.composite_channel(channel='all_channels', image=cropped_img,
operator='over', left=255, top=0)
accent_img.gaussian_blur(3.0, 1.0)
opacity_mask = new_blank_png(req_width, req_height, color=Color('white'))
left_field = new_blank_png(260, req_height, Color('black'))
right_field = new_blank_png(290, req_height, Color('white'))
opacity_mask.composite(left_field, 0, 0)
opacity_mask.composite(right_field, 260+75, 0)
gradient_img.rotate(180)
opacity_mask.composite(gradient_img, 260, 0)
accent_img.composite_channel(channel='all_channels', image=opacity_mask,
operator='copy_opacity')
# Now layer the accent image with the child's face
#
accent_img.composite_channel(channel='all_channels', image=face_img,
operator='over')
full_slice = accent_img
# Finally, add the text field on the right of the image.
#
text_field = new_blank_png(212, req_height, color=Color('rgb(190,30,45)'))
text_field_mask = new_blank_png(212, req_height, color=Color('rgb(220,220,220)'))
text_field.composite_channel(channel='all_channels', image=text_field_mask,
operator='copy_opacity')
full_slice.composite(text_field, 384, 0)
draw = Drawing()
draw.font = FONT_BOLD
draw.font_size = 24
draw.fill_color = Color('white')
draw.text(395, 175, "Liam Mulcahy")
draw.font = FONT_REGULAR
draw.font_size = 20
draw.text(395, 200, "Eyes to the Future")
draw.font = FONT_ITALIC
draw.font_size = 20
draw.text(395, 250, 'How dreams of')
draw.text(395, 275, 'future enterprise')
draw.text(395, 300, 'success are')
draw.text(395, 325, 'starting while still')
draw.text(395, 350, 'in nappies!')
draw(full_slice)
#.........这里部分代码省略.........