commit 5002fbeb9164c373f613042a87108297afb15ce9 Author: Leander Hutton Date: Fri Jun 14 15:29:46 2024 -0400 Initial commit diff --git a/README b/README new file mode 100644 index 0000000..2680451 --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +Requires: libexif-dev on Debain or libexif-devel on Fedora/RHEL + +Compile: + +gcc -o exif_viewer exif_viewer.c $(pkg-config --cflags --libs libexif) diff --git a/exif_viewer.c b/exif_viewer.c new file mode 100644 index 0000000..7ea2979 --- /dev/null +++ b/exif_viewer.c @@ -0,0 +1,54 @@ +#include +#include +#include + +// 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 \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; +}