#!/usr/bin/env perl # NAME: # info2xml.pl - save picture info in xml # # SYNOPSIS: # info2xml.pl info.txt # # DESCRIPTION: # My Nikon camera saves info about the pictures in a file called # info.txt. We copy this off the CF card along with the # pictures and this tool converts the info into xml which we # store in "file"-i.xml where "file" matches the basename of the # picture. # # I use mpics.pl to rename the pics to a YYYYmmddNN format which # makes for easy cataloging. It knows about these -i.xml files # and will re-name the -i.xml file so that it still has the # matching basename for the picture it describes. # # BUGS: # I still haven't decided what to do with the -i.xml files ;-) # # AUTHOR: # Simon J. Gerraty # # RCSid: # $Id: info2xml.pl,v 1.1 2003/01/12 09:26:56 sjg Exp $ # # @(#)Copyright (c) 2002 Simon J. Gerraty. All rights reserved. # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to use, modify and distribute this source code # is granted subject to the following conditions. # 1/ that the above copyright notice and this notice # are preserved in all copies and that due credit be given # to the author. # 2/ that any changes to this code are clearly commented # as such so that the author does not get blamed for bugs # other than his own. # 3/ If there is an accompanying License file its provisions # must also be met. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # if ($0 =~ m,^(.*)/([^/]+)$,) { $Mydir = $1; $Myname = $2; } else { $Mydir = '.'; $Myname = $0; } $pic = ''; $pic_tag = 'picture-information'; %Tag = ('exp-+/-', 'exposure-compensation' ); sub elt { local($t, $data) = @_; local($tag) = $Tag{$t} || $t; printf "<%s>%s\n", $tag, $data, $tag; } while (<>) { chop; y/A-Z/a-z/; s/\r//; next if (m/^\s*$/); if (m/^(.+\S)\s+:\s+(.+)/) { $tag=$1; $data=$2; $tag =~ s/\s+$//; $tag =~ s/\s+/-/g; &elt($tag, $data); } elsif (m/^((.+)\.(.+))$/) { if ($pic ne '') { print "\n"; } $pic = $1; $base = $2; $ext = $3; $file = "${base}-i.xml"; open(STDOUT, "> $file") || die; print "<$pic_tag>\n"; &elt('format', $ext); &elt('original-name', $pic); next; } } if ($pic ne '') { print "\n"; close STDOUT; }