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


Python piexif.dump方法代码示例

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


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

示例1: test_load_name_dict

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [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

示例2: test_dump_and_load_specials

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [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

示例3: test_dump_and_load_specials2

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [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

示例4: add_gps_tags

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [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

示例5: write_image

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [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

示例6: set_photo_exif

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [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

示例7: write

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def write(self, filename=None):
        """Save exif data to file."""
        if filename is None:
            filename = self._filename

        exif_bytes = piexif.dump(self._ef)

        with open(self._filename, "rb") as fin:
            img = fin.read()
        try:
            piexif.insert(exif_bytes, img, filename)

        except IOError:
            type, value, traceback = sys.exc_info()
            print >> sys.stderr, "Error saving file:", value 
开发者ID:mapillary,项目名称:mapillary_tools,代码行数:17,代码来源:exif_write.py

示例8: test_load_tif

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_load_tif(self):
        exif = piexif.load(INPUT_FILE_TIF)
        zeroth_ifd = exif["0th"]
        exif_bytes = piexif.dump({"0th":zeroth_ifd})

        im = Image.new("RGB", (8, 8))
        o = io.BytesIO()
        im.save(o, format="jpeg", exif=exif_bytes)
        im.close()
        exif2 = piexif.load(o.getvalue())
        zeroth_ifd2 = exif2["0th"]
        self.assertDictEqual(zeroth_ifd, zeroth_ifd2) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:14,代码来源:s_test.py

示例9: test_load_tif_m

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_load_tif_m(self):
        with open(INPUT_FILE_TIF, "rb") as f:
            tif = f.read()
        exif = piexif.load(tif)
        zeroth_ifd = exif["0th"]
        exif_bytes = piexif.dump({"0th":zeroth_ifd})

        im = Image.new("RGB", (8, 8))
        o = io.BytesIO()
        im.save(o, format="jpeg", exif=exif_bytes)
        im.close()
        exif2 = piexif.load(o.getvalue())
        zeroth_ifd2 = exif2["0th"]
        self.assertDictEqual(zeroth_ifd, zeroth_ifd2) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:16,代码来源:s_test.py

示例10: test_load_from_pilImage_property

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_load_from_pilImage_property(self):
        o = io.BytesIO()
        i = Image.open(INPUT_FILE1)
        exif = i.info["exif"]
        exif_dict = piexif.load(exif)
        exif_bytes = piexif.dump(exif_dict)
        i.save(o, "jpeg", exif=exif_bytes)
        i.close()
        o.seek(0)
        Image.open(o).close() 
开发者ID:hMatoba,项目名称:Piexif,代码行数:12,代码来源:s_test.py

示例11: test_load_unicode_filename

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_load_unicode_filename(self):
        input_file = os.path.join(u"tests", u"images", u"r_sony.jpg")
        exif = piexif.load(input_file)
        e = load_exif_by_PIL(input_file)
        self._compare_piexifDict_PILDict(exif, e, p=False)

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

示例12: test_dump

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_dump(self):
        exif_dict = {"0th":ZEROTH_IFD, "Exif":EXIF_IFD, "GPS":GPS_IFD}
        t = time.time()
        exif_bytes = piexif.dump(exif_dict)
        t_cost = time.time() - t
        print("'dump': {}[sec]".format(t_cost))
        im = Image.new("RGB", (8, 8))

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

示例13: test_dump_fail

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_dump_fail(self):
        with open(os.path.join("tests", "images", "large.jpg"), "rb") as f:
            thumb_data = f.read()
        exif_dict = {"0th":ZEROTH_IFD,
                     "Exif":EXIF_IFD,
                     "GPS":GPS_IFD,
                     "Interop":INTEROP_IFD,
                     "1st":FIRST_IFD,
                     "thumbnail":thumb_data}
        with self.assertRaises(ValueError):
            piexif.dump(exif_dict) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:13,代码来源:s_test.py

示例14: test_dump_fail2

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_dump_fail2(self):
        exif_ifd = {ExifIFD.DateTimeOriginal: 123}
        exif_dict = {"Exif":exif_ifd}
        with self.assertRaises(ValueError):
            piexif.dump(exif_dict) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:7,代码来源:s_test.py

示例15: test_dump_fail3

# 需要导入模块: import piexif [as 别名]
# 或者: from piexif import dump [as 别名]
def test_dump_fail3(self):
        exif_ifd = {ExifIFD.OECF: 1}
        exif_dict = {"Exif":exif_ifd}
        with self.assertRaises(ValueError):
            piexif.dump(exif_dict) 
开发者ID:hMatoba,项目名称:Piexif,代码行数:7,代码来源:s_test.py


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