写真の整理で一番大変なのが、タグ付けです
通常は手作業で行います
イベントで撮った写真のタグは、一括で登録できます
でも一枚一枚に詳細なタグも付けたいですので、結局手作業になります
なにか、いい方法はないでしょうか
自動でタグを生成するのは、AIでできますが、無料枠だと一度にできるファイル数が10枚程度と少ないです
少なければそれでもいいかなと思いますが!
いろいろ探すと、オープンソースのが見つかりました
windowsのバイナリがあります
使ってみるとそれなりの速度でタグが生成されます
XMPができます
写真における「.xmp」ファイルとは、Adobeの写真編集ソフト(LightroomやCamera Rawなど)で使用される調整データやメタデータが記録されたテキストファイルです
中身はXMLです
生成されたタグは英語ですが、それなりに写真を解析しているようです
そこでプログラムを作って、タグを取得し、日本語してみました
データベースに登録できるSQLを作りました
プログラムは
import xml.etree.ElementTree as ET
import csv
import asyncio
from googletrans import Translator # Or whichever library you are using
import glob, os
def getTags(xmp_string):
root = ET.fromstring(xmp_string)
ns = {"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"}
li_elements = root.findall(".//rdf:li", namespaces=ns)
tags = [elem.text for elem in li_elements if elem.text is not None]
w=""
for item in tags:
if (item!="st" and ("st|" not in item)):
w=w+";"+item
return w
async def main( ):
xmp_files =glob.glob("*.xmp")
for xmp in xmp_files:
with open(xmp, 'r', encoding='utf-8') as f:
xmpdata = f.read()
w=getTags(xmpdata)
translator = Translator()
trans_text = await translator.translate(w, dest='ja')
f=xmp.replace("jpg.xmp","webp")
f=xmp.replace("JPG.xmp","webp")
print(f"insert into photos (filename,tags) values('{f}','{trans_text.text}')")
asyncio.run(main())



