Exif Details

説明

メディアファイルの詳細な EXIF 情報を取得します。

取得データ

  • FILE
  • EXIF
  • GPS

兄弟版プラグイン

  • このプラグインで生成されたタグは、以下のプラグインで使用することができます。
  • Exif Caption.

感謝!テストデータの提供

スニペット 1 & 3 を使用したサンプル

フィルターフックとアクションフックの使い方サンプル

  • サンプルスニペット1
/**  ==================================================
 * Sample snippet 1
 *
 * The original filter hook('exif_details_data'),
 * which changes the display when retrieving an Exif and storing it in metadata.
 * The following changes the display of the shooting date and time.
 *
 * @param array $exifdatas  exifdatas.
 * @param int   $id  id.
 */
function exif_details_change( $exifdatas, $id ) {
    if ( array_key_exists( 'DateTimeOriginal', $exifdatas ) ) {
        $shooting_date = str_replace( ':', '-', substr( $exifdatas['DateTimeOriginal'], 0, 10 ) );
        $shooting_time = substr( $exifdatas['DateTimeOriginal'], 10 );
        $exifdatas['DateTimeOriginal'] = $shooting_date . $shooting_time;
    }
    return $exifdatas;
}
add_filter( 'exif_details_data', 'exif_details_change', 10, 2 );
  • サンプルスニペット2
/**  ==================================================
 * Sample snippet 2
 *
 * Retrieve the post metadata and add the date and time of the shooting to the title of the media page.
 * Execute the original action hook('exif_details_update') in the function.
 *
 * @param array $title  title.
 * @param int   $id  id.
 */
function media_title( $title, $id ) {
    $datetime = null;
    if ( is_attachment() ) {
        do_action( 'exif_details_update', $id );
        $exifdatas = get_post_meta( $id, '_exif_details', true );
        if ( ! empty( $exifdatas ) && array_key_exists( 'DateTimeOriginal', $exifdatas ) ) {
            $datetime = ' Date:' . $exifdatas['DateTimeOriginal'];
        }
    }
    return $title . $datetime;
}
add_filter( 'the_title', 'media_title', 10, 2 );
  • サンプルスニペット3
/**  ==================================================
 * Sample snippet 3
 *
 * When adding new media, insert the processed data into the caption.
 * Use the original action hook ('exif_details_update') with function.
 *
 * @param array $metadata  metadata.
 * @param int   $id  id.
 */
function media_caption( $metadata, $id ) {
    $mime_type = get_post_mime_type( $id );
    if ( in_array( $mime_type, array( 'image/jpeg', 'image/tiff' ) ) ) {
        do_action( 'exif_details_update', $id );
        $exifdatas = get_post_meta( $id, '_exif_details', true );
        if ( ! empty( $exifdatas ) ) {
            $camera = null;
            $f_number = null;
            $s_speed = null;
            $iso = null;
            $date = null;
            $googlemap = null;
            if ( array_key_exists( 'Model', $exifdatas ) ) {
                $camera = 'Camera:' . $exifdatas['Model'];
            }
            if ( array_key_exists( 'ApertureFNumber', $exifdatas ) ) {
                $f_number = 'F-number:' . $exifdatas['ApertureFNumber'];
            }
            if ( array_key_exists( 'ExposureTime', $exifdatas ) ) {
                $s_speed = 'Shutter speed:' . $exifdatas['ExposureTime'];
            }
            if ( array_key_exists( 'ISOSpeedRatings', $exifdatas ) ) {
                $isodata = json_decode( $exifdatas['ISOSpeedRatings'] );
                if ( is_array( $isodata ) ) {
                    $iso = 'ISO:' . $isodata[0];
                } else {
                    $iso = 'ISO:' . $isodata;
                }
            }
            if ( array_key_exists( 'DateTimeOriginal', $exifdatas ) ) {
                $date = 'Date:' . $exifdatas['DateTimeOriginal'];
            }
            if ( array_key_exists( 'latitude_dd', $exifdatas ) && array_key_exists( 'longtitude_dd', $exifdatas ) ) {
                $googlemap = '<a href="https://www.google.com/maps?q=' . $exifdatas['latitude_dd'] . ',' . $exifdatas['longtitude_dd'] . '">Google Map</a>';
            }
            $caption = sprintf( '%1$s %2$s %3$s %4$s %5$s %6$s', $camera, $f_number, $s_speed, $iso, $date, $googlemap );
            $caption = rtrim( $caption );
            $caption = preg_replace( '/\s(?=\s)/', '', $caption );
            $media_post = array(
                'ID'           => $id,
                'post_excerpt' => $caption,
            );
            wp_update_post( $media_post );
        }
    }
    return $metadata;
}
add_filter( 'wp_generate_attachment_metadata', 'media_caption', 10, 2 );

スクリーンショット

  • 表示画面
  • スニペット 1 & 2 を使用したサンプル
  • スニペット 1 & 3 を使用したサンプル

インストール

  1. /wp-content/plugins/ディレクトリ以下にexif-detailsディレクトリをアップロードします。
  2. WordPress の “プラグイン” メニューから有効化してください。

FAQ

ありません

評価

このプラグインにはレビューがありません。

貢献者と開発者

Exif Details はオープンソースソフトウェアです。以下の人々がこのプラグインに貢献しています。

貢献者

“Exif Details” は5ロケールに翻訳されています。 翻訳者のみなさん、翻訳へのご協力ありがとうございます。

“Exif Details” をあなたの言語に翻訳しましょう。

開発に興味がありますか ?

コードを閲覧するか、SVN リポジトリをチェックするか、開発ログRSS で購読してみてください。

変更履歴

1.09

json_encode を wp_json_encode へ変更しました。

1.08

WordPress 6.4 に対応しました。
PHP 8.0 が必須になりました。

1.07

PHP 8.0 以降に対応しました。

1.06

WordPress 5.6 に対応しました。

1.05

オリジナル画像の問題を修正しました。

1.04

readme.txt を変更しました。

1.03

GPS データの問題を修正しました。

1.02

スラッシュで区切られたデータの問題を修正しました。
readme.txt を変更しました。

1.01

値が配列の場合、JSON として保存されます。

1.00

初回リリース。