Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Organising photos into a list (O/T)



Tim Haynes wrote:
> zzapper <david@xxxxxxxxxx> writes:
> > I needed to organise about 60 images into a numerical list. I started by
> > grouping them with a prefix 0001, 0002, 0003 and then using an extra
> > digit to order within the group. I ended up using Windows Explorer and it
> > was an unsatisfactory iterative process. Is this one of those cases where
> > the power of zsh or unix is of no use?
> 
> Depends what criteria you mean by `organize ... into a numerical list'.

Yes, indeed.

> It's a piece of cake to use $SHELL to iterate something like exiftool
> across files and extract one or two fields

The following actually uses identify, which is quite slow since it
extracts far too much information; however, I have it installed.  It
sorts by the first occurrence of the date and time in the metadata:
I've got JPEGs labelled with "Date Time", "Date Time Original" and "Date
Time Digitized" and I've made the code agnostic.  The output is one file
per line in date and time order.  Of course if your files on disk have
the correct (filesystem rather than file metadata) date and time, this
isn't what you want.  But you didn't say.


array=()
for f in *.jpg; do identify -verbose $f | while read line; do
if [[ $line = *Date*Time*:\ (#b)(<->:<->:<->)\ (<->:<->:<->). ]]; then
array+=(${match[1]}:${match[2]}:$f)
break
fi
done
done
print -l ${${(o)array}##*:}


It should be straightforward to generalize.  Oliver has a method of
doing this sort of thing with extended filesystem attributes---you only
need to extract the metadata once, thereafter it's associated with the
file in a way that can quickly be extracted by getfattr.  I believe he
wrote an article about it for (the US) Linux Magazine.  Under Windows
you'd need to do something different.

Meanwhile, yum has been installing exiftool, so here's the equivalent...
exiftool allows you to extract specific tags, but as I said I've
deliberately made it agnostic about which date and time tag it matches.
This is much faster.


array=()
for f in *.jpg; do exiftool $f | while read line; do
if [[ $line = Date/Time*:\ (#b)(<->:<->:<->)\ (<->:<->:<->) ]]; then
array+=(${match[1]}:${match[2]}:$f)
break
fi
done
done
print -l ${${(o)array}##*:}


If by "order into a numerical list" you mean you want the output
numbered, you can pipe the print -l output into cat -n.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



Messages sorted by: Reverse Date, Date, Thread, Author