mcpField
I
image-metadata-tool

image-metadata-tool

github.com/dkyazzentwatwaクリエイティブ・メディア12468 回インストール29 週間前に更新
リポジトリ

image-metadata-tool について

image-metadata-tool は、画像の EXIF データを抽出・管理する Python ライブラリとコマンドラインツールです。写真整理やプライバシー確認に向けて、バッチ分析、GPS マップ生成、メタデータ削除を行えます。

主な機能

  1. 01カメラ、設定、日時、寸法の抽出
  2. 02GPS 座標の読み取りと場所の地図表示
  3. 03向きを残したメタデータ削除
  4. 04画像フォルダーの一括処理
  5. 05JSON、CSV、HTML レポートの出力

活用シーン

  1. 01取り込んだ写真を日時やカメラ別に整理
  2. 02共有前に位置情報の有無を確認
  3. 03位置情報付きの旅行写真からインタラクティブマップを作成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill image-metadata-tool

インストール後、Claude Code で/image-metadata-toolを入力して読み込まれたか確認します。

同梱ファイルscripts/image_metadata.pyscripts/requirements.txt

詳細

画像メタデータツール

GPS マッピングとプライバシー機能を備えた、画像の EXIF メタデータの抽出、分析、管理を行います。

機能

  • EXIF の抽出:カメラ、レンズ、設定、タイムスタンプ
  • GPS データ:座標の抽出、場所の地図表示
  • メタデータの削除:プライバシー保護のため EXIF を削除
  • 一括処理:複数の画像を処理
  • 地図の生成:写真から位置情報の地図を作成
  • エクスポート:JSON、CSV、HTML レポート

クイックスタート

from image_metadata import ImageMetadata

meta = ImageMetadata()
meta.load("photo.jpg")

# Get all metadata
info = meta.extract()
print(f"Camera: {info['camera']}")
print(f"Date: {info['datetime']}")

# Get GPS coordinates
gps = meta.get_gps()
if gps:
    print(f"Location: {gps['latitude']}, {gps['longitude']}")

CLI の使用方法

# Extract metadata
python image_metadata.py --input photo.jpg

# Extract with GPS info
python image_metadata.py --input photo.jpg --gps

# Batch extract from folder
python image_metadata.py --input ./photos/ --output metadata.csv

# Generate location map
python image_metadata.py --input ./photos/ --map locations.html

# Strip metadata (create clean copy)
python image_metadata.py --input photo.jpg --strip --output clean_photo.jpg

# Batch strip metadata
python image_metadata.py --input ./photos/ --strip --output ./clean_photos/

# JSON output
python image_metadata.py --input photo.jpg --json

# Get specific fields
python image_metadata.py --input photo.jpg --fields camera,datetime,gps,dimensions

API リファレンス

ImageMetadata クラス
class ImageMetadata:
    def __init__(self)

    # Loading
    def load(self, filepath: str) -> 'ImageMetadata'

    # Extraction
    def extract(self) -> dict
    def get_camera_info(self) -> dict
    def get_datetime(self) -> dict
    def get_gps(self) -> dict
    def get_dimensions(self) -> dict
    def get_all_exif(self) -> dict

    # Privacy
    def strip_metadata(self, output: str, keep_orientation: bool = True) -> str
    def has_location(self) -> bool

    # Batch operations
    def extract_batch(self, folder: str, recursive: bool = False) -> list
    def strip_batch(self, input_folder: str, output_folder: str) -> list

    # Maps
    def generate_map(self, images: list, output: str) -> str

    # Export
    def to_json(self, output: str) -> str
    def to_csv(self, output: str) -> str

抽出されるメタデータ

カメラ情報
camera_info = meta.get_camera_info()

# Returns:
{
    "make": "Canon",
    "model": "EOS R5",
    "lens": "RF 24-70mm F2.8 L IS USM",
    "lens_id": "61",
    "software": "Adobe Photoshop 24.0",
    "serial_number": "012345678901"
}
撮影設定
settings = meta.extract()["settings"]

# Returns:
{
    "exposure_time": "1/250",
    "f_number": 2.8,
    "iso": 400,
    "focal_length": 50,
    "focal_length_35mm": 50,
    "exposure_program": "Aperture priority",
    "metering_mode": "Pattern",
    "flash": "No flash",
    "white_balance": "Auto"
}
GPS データ
gps = meta.get_gps()

# Returns:
{
    "latitude": 37.7749,
    "longitude": -122.4194,
    "altitude": 10.5,
    "altitude_ref": "Above sea level",
    "timestamp": "2024-01-15 14:30:00",
    "direction": 180.5,
    "speed": 0,
    "maps_url": "https://maps.google.com/maps?q=37.7749,-122.4194"
}
タイムスタンプ
datetime_info = meta.get_datetime()

# Returns:
{
    "original": "2024-01-15 14:30:00",
    "digitized": "2024-01-15 14:30:00",
    "modified": "2024-01-16 10:00:00",
    "timezone": "+00:00"
}
画像の寸法
dims = meta.get_dimensions()

# Returns:
{
    "width": 8192,
    "height": 5464,
    "megapixels": 44.8,
    "orientation": "Horizontal",
    "resolution_x": 300,
    "resolution_y": 300,
    "resolution_unit": "inch"
}

出力の全体

info = meta.extract()

# Returns:
{
    "file": {
        "name": "IMG_1234.jpg",
        "path": "/photos/IMG_1234.jpg",
        "size": 15234567,
        "format": "JPEG"
    },
    "camera": {
        "make": "Canon",
        "model": "EOS R5",
        "lens": "RF 24-70mm F2.8 L IS USM"
    },
    "settings": {
        "exposure_time": "1/250",
        "f_number": 2.8,
        "iso": 400,
        "focal_length": 50
    },
    "datetime": {
        "original": "2024-01-15 14:30:00"
    },
    "gps": {
        "latitude": 37.7749,
        "longitude": -122.4194
    },
    "dimensions": {
        "width": 8192,
        "height": 5464
    }
}

プライバシー機能

メタデータの削除

プライバシー保護のため EXIF データを削除します。

# Strip all metadata
meta.load("original.jpg")
meta.strip_metadata("clean.jpg")

# Keep orientation (prevents rotated images)
meta.strip_metadata("clean.jpg", keep_orientation=True)
位置情報データの確認
meta.load("photo.jpg")
if meta.has_location():
    print("Warning: Photo contains GPS coordinates!")
一括削除
meta.strip_batch("./originals/", "./cleaned/")

GPS マッピング

位置情報の地図を生成

ジオタグ付きの写真からインタラクティブな地図を作成します。

meta = ImageMetadata()

# Batch extract with GPS
images = meta.extract_batch("./vacation_photos/")

# Filter to only geotagged images
geotagged = [img for img in images if img.get("gps")]

# Generate map
meta.generate_map(geotagged, "photo_map.html")

地図には次の情報が含まれます。

  • 各写真の位置を示すマーカー
  • 写真のサムネイルとメタデータを含むポップアップ
  • 密集したエリアのクラスタリング

一括処理

フォルダーから抽出
meta = ImageMetadata()

# All images in folder
results = meta.extract_batch("./photos/")

# Recursive (include subfolders)
results = meta.extract_batch("./photos/", recursive=True)

# Export to CSV
df = pd.DataFrame(results)
df.to_csv("metadata.csv", index=False)
条件によるフィルタリング
results = meta.extract_batch("./photos/")

# Find high ISO photos
high_iso = [r for r in results if r.get("settings", {}).get("iso", 0) > 3200]

# Find photos from specific camera
canon_photos = [r for r in results if "Canon" in r.get("camera", {}).get("make", "")]

# Find photos with GPS
geotagged = [r for r in results if r.get("gps")]

ワークフローの例

写真の整理
meta = ImageMetadata()
results = meta.extract_batch("./camera_import/")

for photo in results:
    date = photo.get("datetime", {}).get("original", "unknown")
    camera = photo.get("camera", {}).get("model", "unknown")
    print(f"{photo['file']['name']}: {date} - {camera}")
プライバシー監査
meta = ImageMetadata()
results = meta.extract_batch("./to_share/")

risky = []
for photo in results:
    if photo.get("gps"):
        risky.append({
            "file": photo["file"]["name"],
            "location": f"{photo['gps']['latitude']}, {photo['gps']['longitude']}"
        })

if risky:
    print(f"Warning: {len(risky)} photos contain location data!")
    for r in risky:
        print(f"  - {r['file']}: {r['location']}")
旅行写真の地図
meta = ImageMetadata()
results = meta.extract_batch("./trip_photos/", recursive=True)

# Generate interactive map
geotagged = [r for r in results if r.get("gps")]
print(f"Found {len(geotagged)} geotagged photos")

meta.generate_map(geotagged, "trip_map.html")

対応フォーマット

  • JPEG/JPG(EXIF を完全にサポート)
  • TIFF(EXIF を完全にサポート)
  • PNG(メタデータのサポートは限定的)
  • HEIC/HEIF(iOS の写真)
  • WebP(メタデータのサポートは限定的)
  • RAW フォーマット(CR2、NEF、ARW など)

依存関係

  • pillow>=10.0.0
  • folium>=0.14.0(地図の生成用)

コメント