\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 ("

Animation of the most recent ". count($truncatedList) ." product images

\n"); // echo "
\n
\n
\n"; echo "
\n
\n"; // now we start writing images. foreach ($truncatedList as $currentImage) { // ../smcd/opdb/goes/winds/2015/02/20150204_1010_hrwv.gif $lastSlash = strrpos($currentImage , '/'); $wholeThing = strlen($currentImage); $currentImageFileNameOnly = substr($currentImage, -($wholeThing - $lastSlash)+1); $dateString = substr($currentImageFileNameOnly,0,8); $usableDate = date("m/d/Y", strtotime($dateString)); $timeString = substr($currentImageFileNameOnly,9,4); $timeString = str_pad($timeString,4,"0",STR_PAD_LEFT) . " GMT"; $DTC = $usableDate . " - " . $timeString; if ($currentImage == $truncatedList[0]) { echo ("
\n"); echo ("

" . $productLabel . " - " . $DTC . "

\n"); echo (" " . $productLabel . " - " . $DTC . "
\n"); } if ($currentImage !== $truncatedList[0]) { echo ("
\n"); echo ("

". $productLabel . " - " . $DTC . "

". $productLabel . " - " . $DTC . "
\n"); } } // close the script that contains the animation images & the containing div. echo "
\n"; include('animationControlButtons.inc'); echo ("
\n"); echo "
\n"; // added 3/17/2020 } //////// $productGroup, $ImagePath, $fileNameStub, $productLabel, $animationMaxSize else { // this still needs work but shouldn't be very important for the animation generator. // it is for the case of no instances of the product being available in the current month or the month before. // put up an attempted link to today's image that we know will be missing so that all the appropriate error messages are triggered $dateString = $today; $usableDate = date("m/d/Y", strtotime($today)); echo "

Tried to load: " . $productLabel . "

"; echo "image: animation not available - contact webmaster\n"; echo "\n
"; } //renderAnimationStackPreload($truncatedList); $GLOBALS['truncatedList2'] = $truncatedList; } ?>