#!/usr/bin/perl use Image::EXIF; $exif = new Image::EXIF; $tag = lc shift @ARGV; print "Tagging with: $tag\n"; foreach $file (@ARGV) { if(-e $file) { print "Checking $file\n"; $exif->file_name($file); $info = $exif->get_image_info(); @commenttags = split('\|', $info->{"Comment"}); if($#commenttags < 0) { # no comments or tags yet $newcommenttags = "|$tag"; } else { print "commenttags: @commenttags\n"; $newcommenttags = shift @commenttags; print "COMMENT: $newcommenttags\n"; if($#commenttags > -1) { $found = 0; @tags = split ' ', $commenttags[0]; foreach $atag (@tags) { $atag = lc $atag; if($atag eq $tag) { $found = 1; } } if(!$found) { push @tags, $tag; } print "TAGS: @tags\n"; $newcommenttags .= "|".join(' ', @tags); } else { $newcommenttags .= "|$tag"; } } print "New string: [$newcommenttags]\n"; system("exifcom $file -fw \"$newcommenttags\""); } else { print "NOT FOUND: $file\n"; } }