Advertisement
Guest User

read-exif

a guest
Jan 15th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <libexif/exif-data.h>
  4.  
  5. static void trim_spaces(char *buf){
  6.     char *s = buf-1;
  7.    
  8.     for (; *buf; ++buf) {
  9.         if (*buf != ' ') s = buf;
  10.     }
  11.     *++s = 0; /* nul terminate the string on the first of the final spaces */
  12. }
  13.  
  14. static char* read_tag(ExifData *ed, ExifIfd eid, ExifTag tag){
  15.     static char result[1024];
  16.     ExifEntry *entry = exif_content_get_entry(ed->ifd[eid], tag);
  17.    
  18.     if (entry){
  19.         char buf[1024];
  20.        
  21.         exif_entry_get_value(entry, buf, sizeof(buf));
  22.         trim_spaces(buf);
  23.    
  24.         if (*buf) strcpy(result, buf);
  25.         else strcpy(result, "NULL");
  26.     }
  27.     else strcpy(result, "NULL");
  28.    
  29.     return result;
  30. }
  31.  
  32. int main(void){
  33.     ExifData *ed;
  34.    
  35.     ed = exif_data_new_from_file("img01.jpg");
  36.    
  37.     if (!ed) {
  38.         printf("File not readable or no EXIF data in file %s\n", argv[1]);
  39.         return 1;
  40.     }
  41.    
  42.     printf("Model : %s\n", read_tag(ed, EXIF_IFD_0, EXIF_TAG_MODEL));
  43.    
  44.     exif_data_unref(ed);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement