Python Image 模块,FLIP_LEFT_RIGHT 实例源码
我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用Image.FLIP_LEFT_RIGHT。
def exif_orientation(im):
"""
Rotate and/or flip an image to respect the image's EXIF orientation data.
"""
try:
exif = im._getexif()
except Exception:
# There are many ways that _getexif fails,we're just going to blanket
# cover them all.
exif = None
if exif:
orientation = exif.get(0x0112)
if orientation == 2:
im = im.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3:
im = im.rotate(180)
elif orientation == 4:
im = im.transpose(Image.FLIP_TOP_BottOM)
elif orientation == 5:
im = im.rotate(-90).transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 6:
im = im.rotate(-90)
elif orientation == 7:
im = im.rotate(90).transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 8:
im = im.rotate(90)
return im
def _CorrectOrientation(self, image, orientation):
"""Use PIL to correct the image orientation based on its EXIF.
See JEITA CP-3451 at http://www.exif.org/specifications.html,
Exif 2.2,page 18.
Args:
image: source PIL.Image.Image object.
orientation: integer in range (1,8) inclusive,corresponding the image
orientation from EXIF.
Returns:
PIL.Image.Image with transforms performed on it. If no correction was
done,it returns the input image.
"""
if orientation == 2:
image = image.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3:
image = image.rotate(180)
elif orientation == 4:
image = image.transpose(Image.FLIP_TOP_BottOM)
elif orientation == 5:
image = image.transpose(Image.FLIP_TOP_BottOM)
image = image.rotate(270)
elif orientation == 6:
image = image.rotate(270)
elif orientation == 7:
image = image.transpose(Image.FLIP_LEFT_RIGHT)
image = image.rotate(270)
elif orientation == 8:
image = image.rotate(90)
return image
def getmask2(self, text, mode="", fill=Image.core.fill):
size, offset = self.font.getsize(text)
im = fill("L", size, 0)
self.font.render(text, im.id, mode=="1")
return im, offset
##
# Wrapper that creates a transposed font from any existing font
# object.
#
# @param font A font object.
# @param orientation An optional orientation. If given,this should
# be one of Image.FLIP_LEFT_RIGHT,Image.FLIP_TOP_BottOM,
# Image.ROTATE_90,Image.ROTATE_180,or Image.ROTATE_270.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。