当前位置: 首页>>代码示例>>Python>>正文


Python ExifTags.TAGS属性代码示例

本文整理汇总了Python中PIL.ExifTags.TAGS属性的典型用法代码示例。如果您正苦于以下问题:Python ExifTags.TAGS属性的具体用法?Python ExifTags.TAGS怎么用?Python ExifTags.TAGS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在PIL.ExifTags的用法示例。


在下文中一共展示了ExifTags.TAGS属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: imreadRotate

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def imreadRotate(fn):
    image=Image.open(fn)
    try:
        for orientation in ExifTags.TAGS.keys():
            if ExifTags.TAGS[orientation]=='Orientation':
                break
        exif=dict(image._getexif().items())
        if exif[orientation] == 3:
            image=image.rotate(180, expand=True)
        elif exif[orientation] == 6:
            image=image.rotate(270, expand=True)
        elif exif[orientation] == 8:
            image=image.rotate(90, expand=True)
    except (AttributeError, KeyError, IndexError):
        # cases: image don't have getexif
        print('dont rotate')
        pass
    return image 
开发者ID:CSAILVision,项目名称:places365,代码行数:20,代码来源:demo_pytorch_CAM.py

示例2: _get_image_original_date

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def _get_image_original_date(f_image):
    img = Image.open(f_image)

    exif_raw = img._getexif()
    if exif_raw is None:
        return None

    exif = {}
    for k, v in exif_raw.items():
        if k in ExifTags.TAGS:
            exif[ExifTags.TAGS[k]] = v

    try:
        return datetime.strptime(exif["DateTimeOriginal"], "%Y:%m:%d %H:%M:%S")
    except:
        return None 
开发者ID:Disfactory,项目名称:Disfactory,代码行数:18,代码来源:utils.py

示例3: read_image

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def read_image(path):
    image = Image.open(path)
    for key in ExifTags.TAGS.keys():
        if ExifTags.TAGS[key] == 'Orientation':
            break
    try:
        exif = dict(image._getexif().items())
    except AttributeError:
        return image
    if exif[key] == 3:
        image = image.rotate(180, expand=True)
    elif exif[key] == 6:
        image = image.rotate(270, expand=True)
    elif exif[key] == 8:
        image = image.rotate(90, expand=True)
    return image 
开发者ID:ruiminshen,项目名称:yolo-tf,代码行数:18,代码来源:detect.py

示例4: exif

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def exif(filename):
    image = Image.open(filename)
    try:
        exif = { TAGS[k]: v for k, v in image._getexif().items() if k in TAGS }
        return exif

    except AttributeError:
        return {}
# }}}


# -- SAMPLE PAIR ATTACK --

# {{{ spa() 
开发者ID:daniellerch,项目名称:aletheia,代码行数:16,代码来源:attacks.py

示例5: get_exif_data

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def get_exif_data(img_file):
    """Read EXIF data from the image.

    img_file: Absolute path to the image file

    Returns: A dictionary containing EXIF data of the file

    Raises: NotAnImageFile if file is not an image
            InvalidExifData if EXIF can't be processed
    """
    try:
        img = Image.open(img_file)
    except (OSError, IOError):
        raise NotAnImageFile

    try:
        # Use TAGS module to make EXIF data human readable
        exif_data = {
            TAGS[k]: v
            for k, v in img._getexif().items()
            if k in TAGS
        }
    except AttributeError:
        raise InvalidExifData

    # Add image format to EXIF
    exif_data['format'] = img.format
    return exif_data 
开发者ID:ronakg,项目名称:smart-image-renamer,代码行数:30,代码来源:smart-image-renamer.py

示例6: generate_file_icon

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def generate_file_icon(file_path):
        """
        Generates a small and a big thumbnail of an image 
        This will make it possible to preview the sent file

        :param file_path: The path to the image 
        """
        im = Image.open(file_path)

        # rotate according to EXIF tags
        try:
            exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS)
            angles = {3: 180, 6: 270, 8: 90}
            orientation = exif['Orientation']
            if orientation in angles.keys():
                im = im.rotate(angles[orientation], expand=True)
        except AttributeError:
            pass  # no EXIF data available

        # Big image
        im.thumbnail((540, 540), Image.ANTIALIAS)
        imgByteArr = io.BytesIO()
        im.save(imgByteArr, format='JPEG2000')
        file_icon = imgByteArr.getvalue()

        # Small image
        #im.thumbnail((64, 64), Image.ANTIALIAS)
        #imgByteArr = io.BytesIO()
        #im.save(imgByteArr, format='JPEG2000')
        #small_file_icon = imgByteArr.getvalue()

        return file_icon 
开发者ID:hexway,项目名称:apple_bleee,代码行数:34,代码来源:util.py

示例7: initExif

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def initExif(self,image):
        """gets any Exif data from the photo"""
        try:
            self.exif_info={
                ExifTags.TAGS[x]:y
                for x,y in image._getexif().items()
                if x in ExifTags.TAGS
            }
            self.exifvalid=True
        except AttributeError:
            print ("Image has no Exif Tags")
            self.exifvalid=False 
开发者ID:PacktPublishing,项目名称:Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition,代码行数:14,代码来源:photohandler.py

示例8: extract_exif

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def extract_exif(self, img):
        if not hasattr(img, '_getexif'):
            return

        exif = img._getexif()
        if exif is None:
            return

        make, model = '', ''
        for num, value in exif.items():
            try:
                tag = ExifTags.TAGS[num]
            except KeyError:
                log.warning("Unknown EXIF code: %s", num)
                continue
            if tag == 'DateTimeOriginal':
                self.update('created_at', self.parse_exif_date(value))
            if tag == 'DateTime':
                self.update('date', self.parse_exif_date(value))
            if tag == 'Make':
                make = value
            if tag == 'Model':
                model = value

        generator = ' '.join((make, model))
        self.update('generator', generator.strip()) 
开发者ID:occrp-attic,项目名称:ingestors,代码行数:28,代码来源:image.py

示例9: generate_file_icon

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def generate_file_icon(file_path):
        """
        Generates a small and a big thumbnail of an image
        This will make it possible to preview the sent file

        :param file_path: The path to the image
        """
        im = Image.open(file_path)

        # rotate according to EXIF tags
        try:
            exif = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items() if k in ExifTags.TAGS)
            angles = {3: 180, 6: 270, 8: 90}
            orientation = exif['Orientation']
            if orientation in angles.keys():
                im = im.rotate(angles[orientation], expand=True)
        except (AttributeError, KeyError):
            pass  # no EXIF data available

        # Big image
        im.thumbnail((540, 540), Image.ANTIALIAS)
        imgByteArr = io.BytesIO()
        im.save(imgByteArr, format='JPEG2000')
        file_icon = imgByteArr.getvalue()

        # Small image
        # im.thumbnail((64, 64), Image.ANTIALIAS)
        # imgByteArr = io.BytesIO()
        # im.save(imgByteArr, format='JPEG2000')
        # small_file_icon = imgByteArr.getvalue()

        return file_icon 
开发者ID:seemoo-lab,项目名称:opendrop,代码行数:34,代码来源:util.py

示例10: process_exif_data

# 需要导入模块: from PIL import ExifTags [as 别名]
# 或者: from PIL.ExifTags import TAGS [as 别名]
def process_exif_data(self):
        """Extract EXIF data from the image and add it to the model"""
        # pylint: disable=protected-access
        # Re-open the image
        self.image.open()
        image_file = StringIO(self.image.read())
        image_file.seek(0)

        # Open the image
        original = PILImage.open(image_file)

        # Find out if it is an image with EXIF data
        if hasattr(original, '_getexif'):
            exif = original._getexif()
            if exif:
                # Match the EXIF field codes to the tag name
                self.exif = {
                    ExifTags.TAGS[code]: value
                    for (code, value) in original._getexif().items()
                    if code in ExifTags.TAGS
                }

                try:
                    # Save the image
                    self.save(process=False, update_fields=['exif'])
                except UnicodeDecodeError:
                    # Oh well
                    pass

        # Close out the file
        image_file.close() 
开发者ID:ofa,项目名称:connect,代码行数:33,代码来源:models.py


注:本文中的PIL.ExifTags.TAGS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。