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


Python piexif.load方法代码示例

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


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

示例1: _open_image

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def _open_image(url):
    """
    Read an image from a URL and convert it into a PIL Image object
    :param url: the URL from where to read the image
    :return: the PIL image object with the EXIF data
    """

    try:
        response = requests.get(url)
        img_bytes = BytesIO(response.content)
        img = Image.open(img_bytes)
        # Preserve EXIF metadata
        if 'exif' in img.info:
            exif = piexif.load(img.info['exif'])
        else:
            exif = None
        return img, exif
    except requests.exceptions.RequestException:
        print('Error loading image data') 
开发者ID:creativecommons,项目名称:cccatalog-api,代码行数:21,代码来源:watermark.py

示例2: test_load_name_dict

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def test_load_name_dict(self):
        thumbnail_io = io.BytesIO()
        thumb = Image.open(INPUT_FILE2)
        thumb.thumbnail((40, 40))
        thumb.save(thumbnail_io, "JPEG")
        thumb.close()
        thumb_data = thumbnail_io.getvalue()
        exif_dict = {"0th":ZEROTH_IFD,
                     "Exif":EXIF_IFD,
                     "GPS":GPS_IFD,
                     "Interop":INTEROP_IFD,
                     "1st":FIRST_IFD,
                     "thumbnail":thumb_data}
        exif_bytes = piexif.dump(exif_dict)
        im = Image.new("RGB", (80, 80))

        o = io.BytesIO()
        im.save(o, format="jpeg", exif=exif_bytes)
        im.close()
        o.seek(0)
        exif = piexif.load(o.getvalue(), True)
        print(exif) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:24,代码来源:s_test.py

示例3: test_dump_and_load

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def test_dump_and_load(self):
        exif_dict = {"0th":ZEROTH_IFD, "Exif":EXIF_IFD, "GPS":GPS_IFD}
        exif_bytes = piexif.dump(exif_dict)
        im = Image.new("RGB", (8, 8))

        o = io.BytesIO()
        im.save(o, format="jpeg", exif=exif_bytes)
        im.close()
        o.seek(0)
        exif = piexif.load(o.getvalue())
        zeroth_ifd, exif_ifd, gps_ifd = exif["0th"], exif["Exif"], exif["GPS"]
        zeroth_ifd.pop(ImageIFD.ExifTag) # pointer to exif IFD
        zeroth_ifd.pop(ImageIFD.GPSTag) # pointer to GPS IFD
        self.assertDictEqual(ZEROTH_IFD, zeroth_ifd)
        self.assertDictEqual(EXIF_IFD, exif_ifd)
        self.assertDictEqual(GPS_IFD, gps_ifd) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:18,代码来源:s_test.py

示例4: test_dump_and_load_specials

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def test_dump_and_load_specials(self):
        """test dump and load special types(SingedByte, SiginedShort, DoubleFloat)"""
        zeroth_ifd_original = {
            ImageIFD.ZZZTestSByte:-128,
            ImageIFD.ZZZTestSShort:-32768,
            ImageIFD.ZZZTestDFloat:1.0e-100,
        }
        exif_dict = {"0th":zeroth_ifd_original}
        exif_bytes = piexif.dump(exif_dict)

        exif = piexif.load(exif_bytes)
        zeroth_ifd = exif["0th"]
        self.assertEqual(
            zeroth_ifd_original[ImageIFD.ZZZTestSByte],
            zeroth_ifd[ImageIFD.ZZZTestSByte]
        )
        self.assertEqual(
            zeroth_ifd_original[ImageIFD.ZZZTestSShort],
            zeroth_ifd[ImageIFD.ZZZTestSShort]
        )
        self.assertEqual(
            zeroth_ifd_original[ImageIFD.ZZZTestDFloat],
            zeroth_ifd[ImageIFD.ZZZTestDFloat]
        ) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:26,代码来源:s_test.py

示例5: test_dump_and_load_specials2

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def test_dump_and_load_specials2(self):
        """test dump and load special types(SingedByte, SiginedShort, DoubleFloat)"""
        zeroth_ifd_original = {
            ImageIFD.ZZZTestSByte:(-128, -128),
            ImageIFD.ZZZTestSShort:(-32768, -32768),
            ImageIFD.ZZZTestDFloat:(1.0e-100, 1.0e-100),
        }
        exif_dict = {"0th":zeroth_ifd_original}
        exif_bytes = piexif.dump(exif_dict)

        exif = piexif.load(exif_bytes)
        zeroth_ifd = exif["0th"]
        self.assertEqual(
            zeroth_ifd_original[ImageIFD.ZZZTestSByte],
            zeroth_ifd[ImageIFD.ZZZTestSByte]
        )
        self.assertEqual(
            zeroth_ifd_original[ImageIFD.ZZZTestSShort],
            zeroth_ifd[ImageIFD.ZZZTestSShort]
        )
        self.assertEqual(
            zeroth_ifd_original[ImageIFD.ZZZTestDFloat],
            zeroth_ifd[ImageIFD.ZZZTestDFloat]
        ) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:26,代码来源:s_test.py

示例6: test_remove_m

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def test_remove_m(self):
        """'remove' on memory.
        """
        o = io.BytesIO()
        with  self.assertRaises(ValueError):
            piexif.remove(I1)
        piexif.remove(I1, o)
        exif_dict = piexif.load(o.getvalue())
        none_dict = {"0th":{},
                     "Exif":{},
                     "GPS":{},
                     "Interop":{},
                     "1st":{},
                     "thumbnail":None}
        self.assertEqual(exif_dict, none_dict)
        Image.open(o).close()

# insert ------ 
开发者ID:hMatoba,项目名称:Piexif,代码行数:20,代码来源:s_test.py

示例7: test_print_exif

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def test_print_exif(self):
        print("\n**********************************************")
        t = time.time()
        exif = piexif.load(INPUT_FILE_PEN)
        t_cost = time.time() - t
        print("'load': {}[sec]".format(t_cost))
        for ifd in ("0th", "Exif", "GPS", "Interop", "1st"):
            print("\n{} IFD:".format(ifd))
            d = exif[ifd]
            for key in sorted(d):
                try:
                    print("  ", key, TAGS[ifd][key]["name"], d[key][:10])
                except:
                    print("  ", key, TAGS[ifd][key]["name"], d[key])
        print("**********************************************")

# test utility methods---------------------------------------------- 
开发者ID:hMatoba,项目名称:Piexif,代码行数:19,代码来源:s_test.py

示例8: verify_metadatas_are_removed

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def verify_metadatas_are_removed(self, file_path):
        # helper function that verifies that the provided image doesn't contain any sensitive metadata
        # empty exif
        self.assertEqual(piexif.load(file_path)["0th"], {}, msg="sensitive exif data left")
        self.assertEqual(piexif.load(file_path)["Exif"], {}, msg="sensitive exif data left")
        self.assertEqual(piexif.load(file_path)["GPS"], {}, msg="sensitive exif data left")
        self.assertEqual(piexif.load(file_path)["1st"], {}, msg="sensitive exif data left")
        # Imagine the following scenario: An image contains sensitive information, it gets modified to hide these.
        # If there is an exif-thumbnail it might represent the previous image and hence could leak those information.
        self.assertEqual(piexif.load(file_path)["thumbnail"], None, msg="The exif thumbnail has not been removed.")

        # verify that xmp is also empty. Normally the xmp content is stored in within the rdf tag
        xmp_file = XMPFiles(file_path=file_path)
        xmp_content = str(xmp_file.get_xmp())
        # this won't match if there are any additional xmp elements left, because they would occur between the opening
        # of the rdf:Description tag and the closing of the rdf:RDF tag.
        sensitive_information = re.findall("  <rdf:Description.*\n </rdf:RDF>", xmp_content)
        self.assertEqual(len(sensitive_information), 1,
                         msg="There are sensitive xmp-tags left:\n\n{}".format(xmp_content))
        xmp_file.close_file() 
开发者ID:iguana-project,项目名称:iguana,代码行数:22,代码来源:test_stripping.py

示例9: get_camera_info

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def get_camera_info(image_file):
    camera = ""
    exif_dict = piexif.load(image_file)
    if piexif.ImageIFD.Make in exif_dict['0th']:
        make = exif_dict['0th'][piexif.ImageIFD.Make].decode('utf-8').rstrip('\x00')
        camera = make
    if piexif.ImageIFD.Model in exif_dict['0th']:
        model = exif_dict['0th'][piexif.ImageIFD.Model].decode('utf-8').rstrip('\x00')
        camera += '_' + model
    if piexif.ExifIFD.LensModel in exif_dict['Exif']:
        lens_model = exif_dict['Exif'][piexif.ExifIFD.LensModel].decode('utf-8').rstrip('\x00')
        camera += '_' + lens_model
    else:
        lens_model = None
    camera = camera.replace(' ', '_')
    return camera, make, model, lens_model 
开发者ID:UASLab,项目名称:ImageAnalysis,代码行数:18,代码来源:exif.py

示例10: add_gps_tags

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def add_gps_tags(path: str, gps_tags: {str: any}):
    """This method will add gps tags to the photo found at path"""
    exif_dict = piexif.load(path)
    for tag, tag_value in gps_tags.items():
        exif_dict["GPS"][tag] = tag_value
    exif_bytes = piexif.dump(exif_dict)
    piexif.insert(exif_bytes, path) 
开发者ID:openstreetcam,项目名称:upload-scripts,代码行数:9,代码来源:exif_processing.py

示例11: read_image

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def read_image(self, image_path):
        """
        开始处理图片
        exifread:读取图片属性
        :return:
        """
        exif_dict = piexif.load(image_path)

        if exif_dict['GPS']:

            # 纬度
            gps_lati_pre = exif_dict['GPS'][2]

            gps_lati = dms_to_gps(gps_lati_pre)

            # 经度
            gps_long_pre = exif_dict['GPS'][4]
            gps_long = dms_to_gps(gps_long_pre)

            # GPS坐标转为高德坐标
            lng, lat = wgs84togcj02(gps_long, gps_lati)

            # print(lng, lat)

            print(f"原图地理位置如下\n经度:{lng}\n纬度:{lat}\n")

            return f'{lng}, {lat}'
        else:
            print(f'抱歉!这张图片不包含地理位置!') 
开发者ID:xingag,项目名称:spider_python,代码行数:31,代码来源:main.py

示例12: write_image

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def write_image(self, image_path, gps_long, gps_lati):
        """
        修改文件夹下所有文件的属性
        :param image_path: 文件夹路径
        :return:
        """
        # 读取图片
        img = Image.open(image_path)

        try:
            exif_dict = piexif.load(img.info['exif'])
        except:
            print('加载文件地理位置异常!')
            return

        # 修改地理位置
        # GPS GPSLatitudeRef:N
        # GPS GPSLatitude:[22, 32, 189/20]
        # GPS GPSLongitudeRef:E
        # GPS GPSLongitude:[114, 1, 689/20]
        exif_dict['GPS'][2] = gps_to_dms(gps_lati)
        exif_dict['GPS'][4] = gps_to_dms(gps_long)

        exif_bytes = piexif.dump(exif_dict)

        # 写入到新的图片中去
        img.save(image_path, 'jpeg', exif=exif_bytes) 
开发者ID:xingag,项目名称:spider_python,代码行数:29,代码来源:main.py

示例13: _load

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def _load(filename):
    """attempt to load hdf5 file and fallback to pickle files if present"""
    if os.path.isfile(filename):
        return read_hdf5(filename)

    stem, ext = os.path.splitext(filename)
    pydat_filename = stem + '.pydat'

    return dill.load(open(pydat_filename, 'rb')) 
开发者ID:matthias-k,项目名称:pysaliency,代码行数:11,代码来源:external_datasets.py

示例14: get_photo_exif

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def get_photo_exif(path):
    """Get EXIF date for a photo, return nothing if there is an error"""
    try:
        exif_dict = piexif.load(path)
        return exif_dict.get("Exif").get(36867)
    except (ValueError, InvalidImageDataError):
        logger = setup_logger()
        logger.debug("Error fetching EXIF data for %s", path)
        return None 
开发者ID:ndbroadbent,项目名称:icloud_photos_downloader,代码行数:11,代码来源:exif_datetime.py

示例15: set_photo_exif

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import load [as 别名]
def set_photo_exif(path, date):
    """Set EXIF date on a photo, do nothing if there is an error"""
    try:
        exif_dict = piexif.load(path)
        exif_dict.get("1st")[306] = date
        exif_dict.get("Exif")[36867] = date
        exif_dict.get("Exif")[36868] = date
        exif_bytes = piexif.dump(exif_dict)
        piexif.insert(exif_bytes, path)
    except (ValueError, InvalidImageDataError):
        logger = setup_logger()
        logger.debug("Error setting EXIF data for %s", path)
        return 
开发者ID:ndbroadbent,项目名称:icloud_photos_downloader,代码行数:15,代码来源:exif_datetime.py


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