コード例 #1
0
def add_to_exif(known):
    for file_name, identified_names in known.items():
        name_string = ""
        for each_name in identified_names:
            if name_string == "":
                name_string = each_name
            else:
                name_string += ", " + each_name
        copyfile(join(r"C:\Users\Book\Desktop\face recogniser\input_image", file_name), join(r"C:\Users\Book\Desktop\face recogniser\tagged_image", file_name))
        i = Image(join(r"C:\Users\Book\Desktop\face recogniser\tagged_image", file_name))
        i.modify_exif({"Exif.Image.Make": name_string})
コード例 #2
0
    def geotag_photo(self, file, lat, lon):
        img = Image(file)
        exif_lat = str(int(lat)) + "/1 " + str(int(
            lat % 1 * 60)) + "/1 " + str(
                int(round((lat % 1 * 60) % 1 * 60, 4) * 100)) + "/100"
        exif_lon = str(int(lon)) + "/1 " + str(int(
            lon % 1 * 60)) + "/1 " + str(
                int(round((lon % 1 * 60) % 1 * 60, 4) * 100)) + "/100"
        if int(lat) < 0:
            exif_lat_ref = 'S'
        else:
            exif_lat_ref = 'N'

        if int(lon) < 0:
            exif_lon_ref = 'W'
        else:
            exif_lon_ref = 'E'
        img.modify_exif({
            'Exif.GPSInfo.GPSLatitudeRef': exif_lat_ref,
            'Exif.GPSInfo.GPSLatitude': exif_lat,
            'Exif.GPSInfo.GPSLongitudeRef': exif_lon_ref,
            'Exif.GPSInfo.GPSLongitude': exif_lon
        })
コード例 #3
0
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:
コード例 #4
0
def write_exif(pic_path, exif_data):
    img = Image(pic_path)
    img.clear_exif()  #这里为防止两套数据冲突清空了已有的原exif
    img.modify_exif(exif_data)
    img.close()
コード例 #5
0
while True:
    fileName = indexFile.readline().strip()
    description = indexFile.readline().strip()
    dateTaken = indexFile.readline().strip()
    if not dateTaken: break  # EOF

    if description != 'delete':
        metadata = Image(path + "\\" + fileName)
        xmp = {'Xmp.dc.description': description}
        metadata.modify_xmp(xmp)

        if dateTaken == next_date_for_pictures:
            # add a second to make the next picture think that it comes next
            split_date = dateTaken.split(":")
            minutes = split_date[3]
            split_date[3] = str(int(minutes) + num_photos_with_date).zfill(2)
            num_photos_with_date += 1
            dateTaken = ":".join(split_date)
        else:
            num_photos_with_date = 1
            next_date_for_pictures = dateTaken

        exif = {
            'Exif.Image.ImageDescription': description,
            'Exif.Photo.DateTimeOriginal': dateTaken
        }
        metadata.modify_exif(exif)
        metadata.close()
    else:
        os.rename(path + "\\" + fileName, path + "\\to_delete\\" + fileName)
コード例 #6
0
                        int(round((lat % 1 * 60) % 1 * 60, 4) * 100)) + "/100"
                exif_lon = str(int(lon)) + "/1 " + str(int(
                    lon % 1 * 60)) + "/1 " + str(
                        int(round((lon % 1 * 60) % 1 * 60, 4) * 100)) + "/100"
                if int(lat) < 0:
                    exif_lat_ref = 'S'
                else:
                    exif_lat_ref = 'N'

                if int(lon) < 0:
                    exif_lon_ref = 'W'
                else:
                    exif_lon_ref = 'E'
                img.modify_exif({
                    'Exif.GPSInfo.GPSLatitudeRef': exif_lat_ref,
                    'Exif.GPSInfo.GPSLatitude': exif_lat,
                    'Exif.GPSInfo.GPSLongitudeRef': exif_lon_ref,
                    'Exif.GPSInfo.GPSLongitude': exif_lon
                })
                #print(exif_lat,"_",exif_lon)
                break
        result[file.path] = {
            'day': day,
            'hour': hour,
            'lat': lat,
            'lon': lon,
            'find': find
        }
        print(file.path, day, hour, lat, lon)

print(result)
コード例 #7
0
def edit_exif():
    i = Image("imgs/1.jpg")
    _dict = {"Exif.Image.Copyright": "津云"}
    i.modify_exif(_dict)