exif_viewer/exif_viewer.c
2024-06-14 15:29:46 -04:00

55 lines
1.3 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <libexif/exif-data.h>
// Prints EXIF entry
// Requires: pointer to ExifEntry
// pointer to user_data
void printExifEntry(ExifEntry *entry, void *user_data) {
char value[1024];
// If entry does not exist just quit
if (!entry) return;
// Get the value as a string
exif_entry_get_value(entry, value, sizeof(value));
if (*value) {
printf("%s: %s\n", exif_tag_get_name(entry->tag), value);
}
}
// showExif
// Gets passed content from exif_data_foreach_content
// calls printExif
void showExif(ExifContent *content, void *user_data) {
if (!content) return;
// Iterate over all entries in the content and print them
exif_content_foreach_entry(content, printExifEntry, user_data);
}
int main(int argc, char *argv[]) {
ExifData *exifData;
const char *file;
if (argc != 2) {
fprintf(stderr, "Usage: %s <file-path>\n", argv[0]);
return 1;
}
file = argv[1];
exifData = exif_data_new_from_file(file);
if (!exifData) {
fprintf(stderr, "Error: Unable to open file %s\n", file);
return 1;
}
// Iterate over all EXIF contents and print entries
exif_data_foreach_content(exifData, showExif, NULL);
// Free the EXIF data
exif_data_unref(exifData);
return 0;
}