\n";
echo "$(window).on('load', function(){ \n";
echo "function preload(imageArray) { \n";
echo "$(imageArray).each(function(){ \n";
echo " $('')[0].src = this; \n";
echo "}); \n }; \n\n";
echo "animationImages = " . $preloadArray . ";\n";
echo "preload(animationImages); \n";
echo "}); \n\n";
}
// renderAnimationStack($productGroup, $ImagePath, $imageStub, $labelStub, $animationMaxSize)
// this function renders image animation stack
// using defaults specified when the function is called.
// $productGroup = "GOES-R Proxy Winds"; // This is what group the product comes from
// $ImagePath = "/www/smcd/opdb/goes/winds/" // This has to be supplied as an absolute path
// for where the images are being generated, starting with /www/ down to just above the YYYY/MM folders
// $fileNameStub = "hrwv.gif" - this is the end of the filename, after the time and date strings,
// the date and time at the front of the product files should be in the form: YYYYMMDD_TTTT_
// $productLabel = "Water Vapor - Winds"; // what product is being animated. Do not repeat / restate the group name in this label
// $animationMaxSize = an integer, this specifies how many images you want in the animation. There can be fewer, but there won't be more than this #.
// The animation will always display the N most recent images: 100, 50, 200, etc.
function renderAnimationStack($productGroup, $ImagePath, $fileNameStub, $productLabel, $animationMaxSize){
// this function captures all the images for this month and last month for a given product
// into an array; sorts them, and renders an image stack of the size specified by the last parameter
list($today, $todayYear, $todayMonth, $todayDate) = getToday();
list($yesterday, $yesterdayYear, $yesterdayMonth, $yesterdayDate) = getYesterday();
// get the latest images that match the filename stub from folder where they are written
$sourceDir = $ImagePath . $todayYear . '/' . $todayMonth . '/';
$lastMonthYear = date('Y', strtotime('-1 month'));
$lastMonth = date('m', strtotime('-1 month'));
$lastMonthDir = $ImagePath . $lastMonthYear . '/' . $lastMonth . '/';
$animationImages = array();
$animImages1 = array();
$animImages2 = array();
$globTarget1 = $ImagePath . $todayYear . '/' . $todayMonth . '/'. '????????_????_' . $fileNameStub;
$globTarget2 = $ImagePath . $lastMonthYear . '/' . $lastMonth . '/' . '????????_????_' . $fileNameStub;
// go get the matching images out of this month and last month (could add a third if I wanted)
$animImages1 = glob($globTarget1, GLOB_NOSORT);
$animImages2 = glob($globTarget2, GLOB_NOSORT);
// is there anything in the arrays?
if (empty($animImages1)) {
$numImg1 = 0;
}
else {
$numImg1= count($animImages1);
}
if (empty($animImages2)) {
$numImg2 = 0;
}
else {
$numImg2= count($animImages2);
}
// This section populates our main source array (animationImages) using all available image matches from 2 months of data
if (($numImg1 !== 0) && ($numImg2 !== 0)) {
$animationImages = array_merge($animImages1,$animImages2);
// if both arrays have content, merge them together to create the list
}
if (($numImg1 == 0) && ($numImg2 == 0)) {
// if both are zero, we have no pics, and should render an error message;
// figure out how to break & render an error message
}
if (($numImg1 !== 0) && ($numImg2 == 0)) {
$animationImages = $animImages1;
}
if ((count($animImages1) == 0) && (count($animImages2) !== 0)) {
$animationImages = $animImages2;
}
if (isset($animationImages[0])) {
// that is, are there any images from the last 2 months.
// sort so newest is first
rsort($animationImages);
// keep the $animationMaxSize newest images in the array to use in the animation
// then sort them oldest to newest and render into the animation
$numImages = count($animationImages);
$truncatedList = array();
$truncatedList = array_slice($animationImages, 0, $animationMaxSize);
sort($truncatedList); // now sorted oldest to newest
// strip the leading '/www' off the front for use in HTML path
foreach ($truncatedList as &$value) {
$value = str_replace('/www','',$value);
}
// set up all the containers
echo ("