import piexif
from PIL import Image
import random
def change_gps(im):
exif_dict = piexif.load(im.info['exif'])
# print(exif_dict)
exif_dict_gps = exif_dict['GPS']# 加载图片中 exif字典GPS字段
print(exif_dict_gps)
# print(exif_gps_lng, exif_gps_lat)
# new_lng_list = [(), ()]
new_exif_jd = ((random.randint(0, 180), 1), (random.randint(0, 100), 1), (random.randint(100,10000), 100)) # 生成随机经度
new_exif_wd = ((random.randint(0, 90), 1), (random.randint(0, 100), 1), (random.randint(100,10000), 100)) # 生成随机纬度
exif_dict['GPS'][4] = new_exif_jd
exif_dict['GPS'][2] = new_exif_wd
exif_dict['GPS'][1] = random.choice(['S', 'N']).encode() # 随机南纬、北纬
exif_dict['GPS'][3] = random.choice(['E', 'W']).encode() # 随机东经、西经
print(exif_dict['GPS'])
return exif_dict
for i in range(500):
im = Image.open('1.jpg') # 修改图片路径
exif_dict = change_gps(im)
exif_bytes = piexif.dump(exif_dict) # 写入图片exif信息
im.save('res_{0}.jpg'.format(i), exif=exif_bytes)
python随机篡改图片exif信息达到修改定位效果
于 2022-05-09 14:18:23 首次发布