def read_key_from_img(img_path): """拿到图像标签数据""" img = Image(img_path) img_info_dict = img.read_iptc() img.close() if "Iptc.Application2.Keywords" in img_info_dict: key_words = img_info_dict["Iptc.Application2.Keywords"] return key_words else: return None
from pyexiv2 import Image img = Image(r'.\pyexiv2\tests\1.jpg') img.read_exif() img.read_iptc() img.read_xmp() img.read_raw_xmp() img.clear_exif() img.read_exif() img.modify_exif({'Exif.Image.Make': 'test-中文-', 'Exif.Image.Rating': ''}) img.read_exif() dict1 = { "Xmp.xmp.CreateDate": "2019-06-23T19:45:17.834", "Xmp.xmp.Rating": "", "Xmp.dc.subject": ["tag1", "tag2", "tag3"] } img.modify_xmp(dict1) img.close() from pyexiv2 import ImageData with open(r'.\pyexiv2\tests\1.jpg', 'rb') as f: with ImageData(f.read()) as img: data = img.read_exif() with open(r'.\pyexiv2\tests\1.jpg', 'rb+') as f: with ImageData(f.read()) as img:
from pyexiv2 import Image img = Image(r'.\pyexiv2\tests\1.jpg') img.read_exif() img.read_iptc() img.read_xmp() img.read_raw_xmp() img.modify_exif({'Exif.Image.Make': 'test-中文-', 'Exif.Image.Rating': ''}) img.read_exif() img.clear_exif() img.read_exif() dict1 = {"Xmp.xmp.CreateDate": "2019-06-23T19:45:17.834", "Xmp.xmp.Rating": "", "Xmp.dc.subject": ["flag1中文", "flag2中文", "flag3中文"]} img.modify_xmp(dict1) img.close()
def read_exif(): i = Image("imgs/2.jpg") print(i.read_exif()) print(i.read_iptc()) print(i.read_xmp())