64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
|
|
from PIL import ExifTags
|
|
from PIL.ExifTags import TAGS
|
|
from tkinter import *
|
|
import tkinter as tk
|
|
from tkinter import ttk, messagebox, filedialog
|
|
import os
|
|
import json
|
|
from PIL import Image
|
|
|
|
def get_name(config,forward,file):
|
|
if config is None:
|
|
return file
|
|
prefix=config['年月']+'-'+config['项目名称']+'-'+forward+'-'+config['项目负责人']+'-'+config['采集人']+'-'
|
|
name=prefix+file
|
|
return name
|
|
def get_exif_data(img):
|
|
"""
|
|
This function returns the exif data of an image as a dictionary.
|
|
"""
|
|
exif_data = {}
|
|
info = img.getexif()
|
|
if info:
|
|
for tag, value in info.items():
|
|
decoded = TAGS.get(tag, tag)
|
|
exif_data[decoded] = value
|
|
return info
|
|
|
|
def copy_and_save_img_exif(img1, img2, save_path="./"):
|
|
"""
|
|
This function copies the exif data from img1 to img2 and saves the new image to save_path.
|
|
"""
|
|
img1_exif = get_exif_data(img1)
|
|
print(img1_exif)
|
|
DateTime=img1_exif.get("DateTime")#like "2025:01:15 17:41:41"
|
|
DateTime=DateTime.split(" ")[0].replace(":", "-")#like "2025-01-15 17-41-41"
|
|
XPComment=img1_exif.get("XPComment").decode("utf-16")#like "DJI_20250115174142_0121_Z"
|
|
print(XPComment)
|
|
img1_exif["XPComment"]="22110".encode("utf-16")#like "22110"
|
|
img2_exif = get_exif_data(img2)
|
|
# img2.save(save_path, exif=img1_exif)
|
|
def specify_name_group_blade(file_path):
|
|
"""
|
|
This function returns the name of the file with the extension.
|
|
"""
|
|
path=os.path.normpath(file_path)
|
|
|
|
sp=path.split("/")
|
|
name=[]
|
|
for i in range(len(sp)):
|
|
if "#" in sp[i]:
|
|
name.append(sp[i].split("#")[0])
|
|
if len(name)==0:
|
|
print("no # in file name")
|
|
return "xxx-xxx-xxx"
|
|
if len(name)>2:
|
|
name=name[-2:]
|
|
name.append('xxx')
|
|
# name.append(os.path.split(file_path)[-1])
|
|
return "-".join(name)
|
|
if __name__ == "__main__":
|
|
|
|
s=os.path.split("/home/user/Desktop/test/IMG_20210812_123456.jpg")
|
|
print(s) |