A little while ago Mike provided some
optional extra code to allow
offsetting of $dayornight. I use that code to extend the 'day' by 60 minutes at the start and end, which is just about right to make the most of daylight with my Panasonic BL-C140 on a clear day. Thanks Mike.

I've now taken that idea and run a little further with it to allow to the archive to vary in size so that it always has slightly more than a days worth of 'daylight' images - yesterday that was 153, today 154.
Maybe others would be interested too? If so here's what I did...
Edit: N.B. This optional modification aims to maintain the archive size at only slightly more than one daylight day's worth of files. If you have a larger archive than that and start using the modification, the extra files will be deleted the first time the code runs! Unless you have made a backup of those extra files will then be lost.In the testtags.txt template in the WD webfiles folder I added this at the bottom (should be after Mike's earlier code, as I use his $night_offset minutes and $day_offset minutes values).
$webcamDayMinutes = round( ( strtotime("$sunset $night_offset minutes") - strtotime("$sunrise $day_offset minutes") ) / 60 );
Then in image-webcam-overlay.php, just after
# How many archived images will be stored
$archivecount = 150;
I added
# skyewright: $archivecount set from a variable calculated by testtags based on day length.
if ( $webcamDayMinutes )
{
$archivecount = round( $webcamDayMinutes / 5 ) + 1; # N.B. Assumes 5 minute upload frequency.
}
As the days grow longer (as is happening here now

) that's all that is really needed, but in the autumn as the days shorten and archivecount decreases, extra code is needed to delete excess files as they become redundant.
To allow for that, just before
# add newest filein image-webcam-overlay.php, I added
# skyewright: remove excess files
$xsFiles = 0;
$xsFileCheck = 1; # Set to 0 to suppress the check.
# If $xsFileCheck is not 0, the code will loop till it fails to find a file to delete.
while ( $xsFileCheck )
{
$xsFileCheck = 0; # unset at start of each loop cycle.
$xsFiles += 1; # increment
$checkNumber = $archivecount+$xsFiles;
$targetfile = $archivedir . $archivefilepre . $checkNumber . '.' .$FileType;
$targetfilethm = $archivedir . $archivefilepre . $checkNumber . '-thm.' .$FileType;
if (file_exists($targetfile))
{
unlink($targetfile);
$xsFileCheck = 1;
}
if ($archivewiththumbs and file_exists($targetfilethm))
{
unlink($targetfilethm);
$xsFileCheck = 1;
}
}
A PHP guru could probably do that more neatly, but if I artificially create excess files they get tidied up, so it seems to work.
