A question about photo file manipulation with multiple folders

Started by Randall, April 08, 2019, 05:39:06 PM

Previous topic - Next topic

Randall

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

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.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Randall

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

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. 
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Randall

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

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

Thanks Hayo,

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

What next?

Hayo Baan

Excellent, I'll see what I can come up for you tomorrow :)
Hayo Baan – Photography
Web: www.hayobaan.nl

Hayo Baan

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:
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

#!/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

This is amazing. 

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

Hayo Baan

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

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

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

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

Hayo Baan – Photography
Web: www.hayobaan.nl