Author Topic: A question about photo file manipulation with multiple folders  (Read 261 times)

Randall

  • Jr. Member
  • **
  • Posts: 16
My apologies in advance if this forum is not well suited to this question.  I am trying to better automate my evolving photo upload process, and (with previous help from this group) I now use this exif tool for part of that process.  My goal is to assign names to files in two folders, so that combined, they are interleaved in a predetermined sequence.  I thought this group might have some good insight for my current quandry, and be able to point me in the right direction!

My current process is to shoot, say, 800 photos at an event.

After light editing, I rename them from the camera's default file name to a descriptive name reflecting the event, using the windows bulk rename tool [giving me: EventName (1), EventName (2), etc].

I then use an exiftool command line on this folder to insert the file name as a caption in the exif data - so the eventual folder upload to Facebook will show the filename in the Facebook description field.

Next I prepare a series of 10 or more 'ad' images, each with a detailed caption, including URL. I repeat these ten images enough times so I can insert one after every tenth image in the main photo set (so if I had 800 'photo' images, I'd prepare 80 'ad' images - eight rotations of the same ten images).

Now I *manually* rename these 80 images to match the event photos from that weekend's shoot, and so they will display every tenth photo in the folder, like so: EventName (10a), EventName (20a), EventName (30a), etc

Then I copy and paste these 80 'ad' photos into the folder with the 800 'event photos, sort by file name, and upload the combined 880 photos to an album on Facebook.  As people scroll through the photos on Facebook, they will see an 'ad' photo with corresponding information and website in the description box, every tenth image.

In my ideal world, I'd like to create a folder of new event images (300-1500), and have previously prepared, a file of 10-15 'ad' images.  I push a button, and magically, there is an 'ad' image inserted in name sequence, after every tenth event image, repeating the sequence enough times necessary to create enough 'ad' photos for the entire set.

I am currently researching more sophisticated file renaming tools like Advanced Renamer, and Bulk Rename Utility, to see if I can at least automate the renaming of the 'ad' images in increments of tens (and still meld the folders manually), but if anyone has useful insight or tips that could assist with this workflow, I would be very pleased to receive your input/suggestions. (Or suggestions as to other websites or forums that might better fit this question)

Thanks!
Randall

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: A question about photo file manipulation with multiple folders
« Reply #1 on: April 08, 2019, 06:28:20 PM »
I'm not quite grasping everything you're doing there, but I will point out that exiftool has extremely powerful renaming ability, especially if you know Regular Expressions (RegEx).

For example, renaming all your images to the "EventName (1)" pattern, you could use:
exiftool "-Filename=EventName (%.C).%e" DIR

Are the "ad" images dupicates of the same picture?  Or are they every 10th picture?  If you wanted to copy out ever tenth picture into another directory for prep, you could use
exiftool -if "not (($FileSequence+1)%10)" -o /prep/Directory DIR
where you replace /prep/Directory with the path to the prep directory and DIR with the main directory.

If you have your "ad" images in a separate directory, you could use
exiftool "-Filename=EventName (%.C0a).%e" DIR
or even rename and merge them by also including the directory path in front of the file name.

Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #2 on: April 08, 2019, 07:11:14 PM »
Thanks StarGeek,

For the 'ad' photos (these are not photos taken as part of part of the event photo sequence, but images that I want to display after every tenth 'event' photo in the finished file set), I typically have somewhere around ten or twelve different images.  I could constrain it to a predetermined number, if it made the task easier (manually, I just repeat back to the start of the list each time I get to the end, so the number doesn't matter).  I use them in repeated rotation, as many times as needed to match the total number of images in the folder.  So with ten 'ad' images, and 800 'event' images, each would be used about 8 times, to make the total of 80 inserted 'ad' images.

What I am manually doing now, and would like to automate, is to take my file of 'ad' photos (let's call them 1.jpg, 2.jpg, 3.jpg, through 10.jpg), and rename them in increments of ten, so they slot in at the right place in the finished folder.

So, in that example, 1.jpg would be copied as Event (10a).jpg, Event (110a).jpg, Event (210a).jpg, Event (310a).jpg, etc...
2.jpg would be copied as Event (20a).jpg, Event (120a).jpg, Event (220a).jpg, Event (320a).jpg, etc...

In an ideal world, the number of 'ad' photos I had in that folder would be irrelevant, as the program would just use each in sequence as needed, reverting to the start of the list again each time it got to the end.

Does that explain better?


StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: A question about photo file manipulation with multiple folders
« Reply #3 on: April 08, 2019, 08:40:11 PM »
I can almost think of a 2 step solution for this (write commands into a temp file, then execute the temp file) but I'm hard pressed to come up with a 1 step solution using exiftool.

You don't mention your OS, but under Windows I'm pretty sure a batch file or under Mac/Linux a bash script would be easier and quicker overall. 
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #4 on: April 08, 2019, 11:37:07 PM »
Thanks.  It's Windows 7, but alas, I am not a programmer.  I am fairly competent within the confines of a spreadsheet, and can execute a file reliably, but haven't the experience and knowledge base to write it.  Pleased to reimburse someone for assistance in putting this together though.

Any recommendations of where I can find someone to help with this?

Thanks,
R.

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 925
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: A question about photo file manipulation with multiple folders
« Reply #5 on: April 09, 2019, 01:36:57 AM »
This really is something that is best done with a small shell script. On a Mac/Linux this would be easiest since the shell itself already is powerful enough but it’s even easier with e.g. Perl or some other scripting language. On windows similar things can be done (especially with Powershell) albeit slightly less comfortably in my opinion.

Since I don’t own a windows system I can’t help you there, but if you already have Perl installed, I can write a little Perl script for you that does what you want. This Perl script would work on windows too.
Hayo Baan – Photography
Web: www.hayobaan.nl

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #6 on: April 09, 2019, 02:20:46 PM »
Thanks Hayo,

I have installed Perl, and would be very pleased to take you up on your offer!

What next?

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 925
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: A question about photo file manipulation with multiple folders
« Reply #7 on: April 09, 2019, 04:15:35 PM »
Excellent, I’ll see what I can come up for you tomorrow :)
Hayo Baan – Photography
Web: www.hayobaan.nl

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 925
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: A question about photo file manipulation with multiple folders
« Reply #8 on: April 10, 2019, 12:14:32 AM »
Hi Randall, below script should do what you want. It expects the event files and ad files in separate directories. The event files must be named "xxx(NR).yyy" where xxx and yyy can be anything and NR is a sequence number. The ad files can be named anything (they are used in natural order).

If you copy below script to a file called e.g. mergeads.pl you can simply call perl mergeads.pl FILES ADS where FILES and ADS are the directories in which you have the event files and ad files respectively.

When run on an ad directory with 4 ads (named 1.jpg, 2.jpg, 3.jpg, 4.jpg) and an event directory with 159 event files (Event (x).jpg) the result would be:
Code: [Select]
Copying ads/1.jpg => files/Event (10a).jpg
Copying ads/2.jpg => files/Event (20a).jpg
Copying ads/3.jpg => files/Event (30a).jpg
Copying ads/4.jpg => files/Event (40a).jpg
Copying ads/1.jpg => files/Event (50a).jpg
Copying ads/2.jpg => files/Event (60a).jpg
Copying ads/3.jpg => files/Event (70a).jpg
Copying ads/4.jpg => files/Event (80a).jpg
Copying ads/1.jpg => files/Event (90a).jpg
Copying ads/2.jpg => files/Event (100a).jpg
Copying ads/3.jpg => files/Event (110a).jpg
Copying ads/4.jpg => files/Event (120a).jpg
Copying ads/1.jpg => files/Event (130a).jpg
Copying ads/2.jpg => files/Event (140a).jpg
Copying ads/3.jpg => files/Event (150a).jpg

Instead of adding the ad every 10nth file, you could choose a different interval. This you can do by changing the value of $adInterval at the beginning of the script.

Hope this does what you wanted.

Cheers,
Hayo

Code: [Select]
#!/usr/bin/perl

# Simple script to "merge" ads into a sequence of files.

# Usage:
#   perl mergeads.pl <FILES-DIR> <AD-DIR>

use v5.14; # for /r regexp
use strict;
use warnings;

use File::Copy qw(copy);

# Add an ad every nth file
my $adInterval = 10;

die "Usage: perl mergeads.pl <FILES-DIR> <AD-DIR>\n" unless $#ARGV == 1 && -d $ARGV[0] && -d $ARGV[1];

my @files = glob("$ARGV[0]/*");
my @ads = glob("$ARGV[1]/*");

# Keep only valid files
@files = grep { /^.*\([0-9]+\)\..*$/ } @files;

die "No valid files found in $ARGV[0]" unless @files;
die "No ads found in $ARGV[1]" unless @ads;

# Sort files
@files = sort fileSort @files; # Sort on event number
@ads = sort @ads; # Use natural sort order

my $nrAds = scalar @ads;
my $adNr = 0;

for (my $fileNr = $adInterval-1; $fileNr <= $#files; $fileNr += $adInterval) {
    my $adFile = $files[$fileNr];
    $adFile =~ s/\(([0-9]*)\)/($1a)/;
    print "Copying $ads[$adNr] => $adFile\n";
    copy $ads[$adNr], $adFile;
    $adNr = ($adNr + 1) % $nrAds;
}

# Sort files based on event number in brackets
sub fileSort {
    my $nr_a = $a =~ s/.*\(([0-9]+)\)\..*/$1/r;
    my $nr_b = $b =~ s/.*\(([0-9]+)\)\..*/$1/r;
    return $nr_a < $nr_b ? -1 : $nr_a > $nr_b ? 1 : 0;
}
Hayo Baan – Photography
Web: www.hayobaan.nl

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #9 on: April 12, 2019, 02:15:28 AM »
This is amazing. 

Excited, and testing to see if I can make it work as you have laid out now...

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 925
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: A question about photo file manipulation with multiple folders
« Reply #10 on: April 12, 2019, 02:36:38 AM »
Hi Randall,

Hope it works for you “out-of-the-box” but if there's anything not working as you like, please let me know!
Hayo Baan – Photography
Web: www.hayobaan.nl

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #11 on: April 12, 2019, 03:29:30 AM »
I felt like I was banging my head against the wall for a couple of hours, seemingly everything was right, yet I couldn't get it to work - then suddenly, I did it slightly differently, and it worked like freakin' magic!  OMG, wow.

I'll have to come back to it tomorrow to better understand what I am doing, but holy crap, this is amazing...

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #12 on: April 12, 2019, 05:25:39 PM »
I have got it all working as I want now.  This is really quite a huge help.  Given how effective this is, it now makes me wonder if some other parts of my process could be automated as well. 

I am shooting two events this weekend, so will give it a thorough test, and be back to you early next week.

Randall

  • Jr. Member
  • **
  • Posts: 16
Re: A question about photo file manipulation with multiple folders
« Reply #13 on: April 30, 2019, 07:54:49 PM »
I popped off a DM, but I wanted to publicly thank you for your assistance, Hayo.

Your script has simplified my work flow tremendously, and saves me a lot of time after each photo shoot.  I really appreciate you taking the time to reply, and offering up such a simple to utilize solution.

 Cheers!   :)

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 925
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: A question about photo file manipulation with multiple folders
« Reply #14 on: May 01, 2019, 02:43:00 AM »
Glad to have been of help!
Hayo Baan – Photography
Web: www.hayobaan.nl