JPEG画像ファイル内部のExif情報を編集

なんとかGPS関係の情報だけを取り除きたい

Exif情報については、

ここがわかりやすい。またExif情報をダンプするプログラムソースも提示していただいています。C++ Builder CEで使えるBorland C Compiler (いつものbcc32c)でコンパイルしてみましょう。ソースのある場所で、例の右クリックからGit Bash hereを選んで

$ bcc32c sample_main.c exif.c
Embarcadero C++ 7.70 for Win32 Copyright (c) 2012-2024 Embarcadero Technologies, Inc.
sample_main.c:
sample_main.c:271:5: warning: implicitly declaring library function 'strcpy' with type 'char *(char *, const char *)' [-Wimplicit-function-declaration]
    strcpy((char*)tag->byteData, "ABCDE");
    ^
sample_main.c:271:5: note: include the header <string.h> or explicitly provide a declaration for 'strcpy'
sample_main.c:322:5: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
    free(p);
    ^
2 warnings generated.
exif.c:
Turbo Incremental Link 6.99 Copyright (c) 1997-2024 Embarcadero Technologies, Inc.

jakeb@Orbit-11 MINGW64 ~/Downloads/exif-master/exif-master/bcc
$ ls -alt
total 424
-rw-r--r-- 1 jakeb 197609 196608  4月  4 11:09 sample_main.tds
-rwxr-xr-x 1 jakeb 197609 113152  4月  4 11:09 sample_main.exe*
drwxr-xr-x 1 jakeb 197609      0  4月  4 11:09 ./
drwxr-xr-x 1 jakeb 197609      0  4月  4 11:09 ../
-rw-r--r-- 1 jakeb 197609  10084  4月  4 09:43 sample_main.c
-rw-r--r-- 1 jakeb 197609  18697  4月  4 09:43 exif.h
-rw-r--r-- 1 jakeb 197609  78706  4月  4 09:43 exif.c

ワーニングが2個出ていますけど、本質的な問題ではなく、バイナリもできています。動かして見ましょう。

$ ./sample_main
usage: C:\Users\jakeb\Downloads\exif-master\exif-master\bcc\sample_main.exe <JPEG FileName> [-v]erbose

jakeb@Orbit-11 MINGW64 ~/Downloads/exif-master/exif-master/bcc
$ ./sample_main test.jpg
[test.jpg] createIfdTableArray: result=4

{0TH IFD}
 - Make: [Apple]
 - Model: [iPod touch]
 - Orientation: 1
 - XResolution: 72/1
 - YResolution: 72/1
 - ResolutionUnit: 2
 - Software: [6.1.4]
 - DateTime: [2013:09:01 09:49:00]
 - YCbCrPositioning: 1
 - ExifIFDPointer: 206
 - GPSInfoIFDPointer: 576

{EXIF IFD}
 - ExposureTime: 1/30
 - FNumber: 12/5
 - ExposureProgram: 2
 - PhotographicSensitivity: 400
 - ExifVersion: 0 2 2 1
 - DateTimeOriginal: [2013:09:01 09:49:00]
 - DateTimeDigitized: [2013:09:01 09:49:00]
 - ComponentsConfiguration: 0x01 0x02 0x03 0x00
 - ShutterSpeedValue: 4035/821
 - ApertureValue: 4845/1918
 - BrightnessValue: 2234/1113
 - MeteringMode: 5
 - Flash: 32
 - FocalLength: 77/20
 - FlashPixVersion: 0 1 0 0
 - ColorSpace: 1
 - PixelXDimension: 960
 - PixelYDimension: 720
 - SensingMethod: 2
 - ExposureMode: 0
 - WhiteBalance: 0
 - FocalLengthIn35mmFormat: 32
 - SceneCaptureType: 0

{GPS IFD}
 - GPSLatitudeRef: [S]
 - GPSLatitude: 69/1 17/100 0/1
 - GPSLongitudeRef: [E]
 - GPSLongitude: 39/1 35/100 0/1
 - GPSAltitudeRef: 0
 - GPSAltitude: 6151/470
 - GPSTimeStamp: 0/1 48/1 3921/100

{1ST IFD}
 - Compression: 6
 - XResolution: 72/1
 - YResolution: 72/1
 - ResolutionUnit: 2
 - JPEGInterchangeFormat: 840
 - JPEGInterchangeFormatLength: 8648

0th IFD : Model = [iPod touch]
Exif IFD : DateTimeOriginal = [2013:09:01 09:49:00]
GPS IFD : GPSLatitude = 69/1 17/100 0/1

ちゃんとtag別に情報が得られていますね。提供されたバイナリのexif_win32.exeを起動すると、

exif抜いたjpgまで作ってるやん?これは上記でコンパイルしたsample_main.cと少し違うものをbuildしたもののようです。ソースの中身を検分すると理由が推測できます。これをなんとかC++ Builder CEから使えるようにするわけですが、元々がCのソースなので、C++で使うのは原理的にできるはずですね。後はstdoutをなんとかするか、stdoutを使わない形で組み込めばいいわけですね。それは次の記事で。

コメント