News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

custom file creation

Started by greenhat, May 25, 2014, 09:55:45 PM

Previous topic - Next topic

greenhat

Hi there,

I'm pretty new to exiftool.

I have 100+ tagged images which I want to import into TiddlyWiki5 (tiddlywiki.com).

All I've managed to do with exiftool so far is output the image file names with tags to a .csv file. for that I used: exiftool -csv -title -subject /Location/of/images > out.csv

Getting the tags like that makes it slightly easier to add them to the wiki, but I can improve my workflow tremendously if I can instruct exiftool to create some custom files for me, from the images. Over at the TiddlyWiki mailing list I asked about the best way to get the IPTC tags into tiddlywiki5 (https://groups.google.com/forum/#!topic/tiddlywikidev/CisH4uZmbnY).

The response I got was to create files in this form:


filename eg: image1.jpg.tid

with the content:

created: 20140414210611111
modified: 20140415011511460
title: image1.jpg
type: image/jpg
tags: tag1 tag2 tag3
source: http://tiddlywiki.com/favicon.ico

Some description text about the image.
Multi line is possible.


If I can do that, "it would be possible to build a TiddlyWiki, that includes those tiddlers. With some transclusion templates, it would be possible to create your desired behaviour." So that's my goal.

Can anyone give me instruction about how to produce such files, with exiftool?

Best regards,

David.

Phil Harvey

Hi David,

You can use the -p option to create output files in any format.  See the application documentation for details.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

greenhat

Hi Phil,

thanks so much!

I've *basically* got it doing what I need to. I created a format file 'TWmetadata':



created: $CreateDate
modified: $ModifyDate
title: $FileName
type: image/jpg
tags: $Keywords
source: $Directory/$FileName



and then used the command exiftool -p TWmetadata /imgsDirectory > out_all.fmt

That's given me a file collecting the metadata I've specified, for every image.

I have a few questions, to tweak the result:


  • How can I vary the command to create one file for each image, sent to a directory? (eg imgsDirectory/metadataOut/)
  • Following the above question, how can I use the image filename as the filename created? (ie a_image.jpg, b_image.jpg > a_image.tid, b_image.tid)
  • Can I somehow set the CreateDate and ModifyDate format to be only numbers? (ie 20140414210611 instead of 2014:04:14 21:06:11)
  • Similarly, can I set Keywords to return the keywords/tags without commas?

Thanks again!

David

Phil Harvey

Hi David,

Quote from: greenhat on May 26, 2014, 06:54:28 PM
1. How can I vary the command to create one file for each image, sent to a directory? (eg imgsDirectory/metadataOut/)

What directory?  All one directory?  The same directories as the images?  A directory hierarchy the same as the images but rooted elsewhere?  All are possible.  The -w option is what you want, but its argument will vary depending on your requirements.

Quote2. Following the above question, how can I use the image filename as the filename created? (ie a_image.jpg, b_image.jpg > a_image.tid, b_image.tid)

Yes.  Same answer.

Quote3. Can I somehow set the CreateDate and ModifyDate format to be only numbers? (ie 20140414210611 instead of 2014:04:14 21:06:11)

This is the function of the -d option.

Quote4. Similarly, can I set Keywords to return the keywords/tags without commas?

Reading about the -sep option will answer this for you.

Plus, there are lots of other useful things that ExifTool can do.  I suggest browsing the options in the application documentation. :)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

greenhat

Thanks so much for your help, Phil.

I was able to follow your pointers within the documentation and piece together the command I needed to run. What I ended up with is:

exiftool -p TWmetadata.fmt /imgsDirectory -w %d/out/%f_%e.tid -d %Y%m%d%H%M%S000 -sep " "


I'll break that down for my reference and for anyone else who it might be helpful for:

-p option 'creates an output file in any format'
TWmetadata.fmt this is my output file template
/imgsDirectory this is the directory all my images are located in (could be Users/home/pictures/imgs-to-add etc.)
-w write...
%d to the same directory (ie my /imgsDirectory)...
/out/ ...in a new folder named 'out'...
%f_%e.tid ...naming the created files from the existing files 'filename'_'extension'.tid ('.tid' is the extension I need for TiddlyWiki)
-d use the date format...
%Y%m%d%H%M%S000 ...YearMonthDayHourMinuteSecond000 (the trailing zeros are for tiddlywiki, which allows for the millisecond a file was created. As I don't have that data or need it, I'm just zeroing it.)
-sep use the separator...
" " a single space. Default is commas, and I don't want commas.

For reference, here is my template file (TWmetadata.fmt):


created: $CreateDate
modified: $ModifyDate
title: $FileName
tags: $Keywords

[img[imgs/$FileName]]




and here is a sample output file (hole1_jpg.tid):

created: 20140520093331000
modified: 20140522204223000
title: hole1.jpg
tags: paving risk trip-hazard

[img[imgs/hole1.jpg]]



A few comments:

* Exiftool is very powerful, and very fast. I've learnt a couple of commands, there is so much more it can do. And what I asked it to do was done maybe a second after I hit enter in the command line.
* It does take some time to learn, and so does the command line. It was interesting to see how commands 'stack' on top of each other; it seems like magic, like an incantation, but I think it's just a lot of logic. I'm still new to the command line I guess. I think it's refreshingly simple, once you see things working. It probably took me an hour to track down the commands in the manual from Phil's post, work out what they did, and how to apply them for my needs. That is a fair bit of time, when I could have got started processing my files one by one, immediately. But now, I can apply those skills any time I need to process any similar images/tags. And Exiftool takes a second where I could take all afternoon, and I'd add errors.
* One thing from the documentation troubled me- the date format said to consult the strftime man page to work out what formatting my system used. I'm on a mac, so I tried to track down the mac strftime man page. But I didn't seem to be able to run the command. So, I browsed the Exiftool documentation some more, and ended up just guessing, based on some example given. And that worked.

Phil Harvey

Excellent.  You obviously have some skills in logic. :)

On my Mac I can type "man strftime" to see the documentation below, but I'm not sure if this man page came with the XCode package that I installed.  The problem is that they are different on different systems, but the common formatting codes are listed here.

- Phil


STRFTIME(3) BSD Library Functions Manual    STRFTIME(3)

NAME
     strftime, strftime_l -- format date and time

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <time.h>

     size_t
     strftime(char *restrict s, size_t maxsize, const char *restrict format,
const struct tm *restrict timeptr);

     #include <time.h>
     #include <xlocale.h>

     size_t
     strftime_l(char *restrict s, size_t maxsize, const char *restrict format,
const struct tm *restrict timeptr, locale_t loc);

DESCRIPTION
     The strftime() function formats the information from timeptr into the
     buffer s, according to the string pointed to by format.

     The format string consists of zero or more conversion specifications and
     ordinary characters.  All ordinary characters are copied directly into
     the buffer.  A conversion specification consists of a percent sign
     ```%''' and one other character.

     No more than maxsize characters will be placed into the array.  If the
     total number of resulting characters, including the terminating NUL char-
     acter, is not more than maxsize, strftime() returns the number of charac-
     ters in the array, not counting the terminating NUL.  Otherwise, zero is
     returned and the buffer contents are indeterminate.

     Although the strftime() function uses the current locale, the
     strftime_l() function may be passed a locale directly. See xlocale(3) for
     more information.

     The conversion specifications are copied to the buffer after expansion as
     follows:-

     %A    is replaced by national representation of the full weekday name.

     %a    is replaced by national representation of the abbreviated weekday
   name.

     %B    is replaced by national representation of the full month name.

     %b    is replaced by national representation of the abbreviated month
   name.

     %C    is replaced by (year / 100) as decimal number; single digits are
   preceded by a zero.

     %c    is replaced by national representation of time and date.

     %D    is equivalent to ``%m/%d/%y''.

     %d    is replaced by the day of the month as a decimal number (01-31).

     %E* %O*
   POSIX locale extensions.  The sequences %Ec %EC %Ex %EX %Ey %EY %Od
   %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow %OW %Oy are supposed to
   provide alternate representations.

   Additionally %OB implemented to represent alternative months names
   (used standalone, without day mentioned).

     %e    is replaced by the day of the month as a decimal number (1-31);
   single digits are preceded by a blank.

     %F    is equivalent to ``%Y-%m-%d''.

     %G    is replaced by a year as a decimal number with century.  This year
   is the one that contains the greater part of the week (Monday as
   the first day of the week).

     %g    is replaced by the same year as in ``%G'', but as a decimal number
   without century (00-99).

     %H    is replaced by the hour (24-hour clock) as a decimal number
   (00-23).

     %h    the same as %b.

     %I    is replaced by the hour (12-hour clock) as a decimal number
   (01-12).

     %j    is replaced by the day of the year as a decimal number (001-366).

     %k    is replaced by the hour (24-hour clock) as a decimal number (0-23);
   single digits are preceded by a blank.

     %l    is replaced by the hour (12-hour clock) as a decimal number (1-12);
   single digits are preceded by a blank.

     %M    is replaced by the minute as a decimal number (00-59).

     %m    is replaced by the month as a decimal number (01-12).

     %n    is replaced by a newline.

     %O*   the same as %E*.

     %p    is replaced by national representation of either "ante meridiem"
   (a.m.)  or "post meridiem" (p.m.)  as appropriate.

     %R    is equivalent to ``%H:%M''.

     %r    is equivalent to ``%I:%M:%S %p''.

     %S    is replaced by the second as a decimal number (00-60).

     %s    is replaced by the number of seconds since the Epoch, UTC (see
   mktime(3)).

     %T    is equivalent to ``%H:%M:%S''.

     %t    is replaced by a tab.

     %U    is replaced by the week number of the year (Sunday as the first day
   of the week) as a decimal number (00-53).

     %u    is replaced by the weekday (Monday as the first day of the week) as
   a decimal number (1-7).

     %V    is replaced by the week number of the year (Monday as the first day
   of the week) as a decimal number (01-53).  If the week containing
   January 1 has four or more days in the new year, then it is week 1;
   otherwise it is the last week of the previous year, and the next
   week is week 1.

     %v    is equivalent to ``%e-%b-%Y''.

     %W    is replaced by the week number of the year (Monday as the first day
   of the week) as a decimal number (00-53).

     %w    is replaced by the weekday (Sunday as the first day of the week) as
   a decimal number (0-6).

     %X    is replaced by national representation of the time.

     %x    is replaced by national representation of the date.

     %Y    is replaced by the year with century as a decimal number.

     %y    is replaced by the year without century as a decimal number
   (00-99).

     %Z    is replaced by the time zone name.

     %z    is replaced by the time zone offset from UTC; a leading plus sign
   stands for east of UTC, a minus sign for west of UTC, hours and
   minutes follow with two digits each and no delimiter between them
   (common form for RFC 822 date headers).

     %+    is replaced by national representation of the date and time (the
   format is similar to that produced by date(1)).

     %-*   GNU libc extension. Do not do any padding when performing numeri-
   cal outputs.

     %_*   GNU libc extension. Explicitly specify space for padding.

     %0*   GNU libc extension. Explicitly specify zero for padding.

     %%    is replaced by `%'.

SEE ALSO
     date(1), printf(1), ctime(3), printf(3), strptime(3), wcsftime(3),
     xlocale(3)

STANDARDS
     The strftime() function conforms to ISO/IEC 9899:1990 (``ISO C90'') with
     a lot of extensions including `%C', `%D', `%E*', `%e', `%G', `%g', `%h',
     `%k', `%l', `%n', `%O*', `%R', `%r', `%s', `%T', `%t', `%u', `%V', `%z',
     and `%+'.

     The peculiar week number and year in the replacements of `%G', `%g', and
     `%V' are defined in ISO 8601: 1988.

BUGS
     There is no conversion specification for the phase of the moon.

     The strftime() function does not correctly handle multibyte characters in
     the format argument.

BSD        November 4, 2004    BSD
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).