Happy New Year 2018 and happy to announce a PHP-script I've been working
on during Christmas, GRUVI (.generate.random.URLs_for.viewing.images.)!

The script randomly picks a predetermined number of pictures from a
chosen web-server location, resizes them to fit the SB Touch and Radio
displays, with or without captions. It renews the selection after som
predefined time interval, and reshuffles the order every time the script
is called from the players.

Notwithstanding som other great SB image viewer utilities out there,
like Picture Gallery, Image Browser, iPeng etc., the script solves some
yet unmet needs I've had for a long time, like random selections of
images, functioning as an automatic screen saver and photo frame,
off-loading my main media server, NAS and players(runs well in the
background on a small RPi3), captioning and configurability, working
with the built-in Image Viewer app on the players with total
independence from the rest of the LMS system and its plugins and such.

Prerequisites:
-Some web server: 
-with access to the photos you want to show
-with PHP installed
-with ImageMagick installed
-which probably has to run on Linux because of my shell calls
-Some patience and and time to tinker a little bit... ;-)

Installation:
-Copy the contents of the zip-file to the hosted folders on the web
server
-Set your wanted global parameters in the main gruvi.php script file
-Set the required execution, file and application path accesses
-Set up your players like this and choose to run the Image Viewer app as
a screen saver if you like:
24289

Then start GRUVI'n!:  :cool:
24288


Enjoy(hopefully)! :)

Vegz78


Code:
--------------------
    
  <?php 
  
  /*  GRUVI
  A random URL image file list generator for the Image Viewer app on the 
Squeezebox Touch and Radio, with:
        -Random selection of files and random shuffle of the lists between 
every call to this PHP-file
        -Locally cached copies of the images with reduced sizes to reduce load 
on LMS, players and network
        -Image files hosted on a web server of your chosing and fittet to the 
players' screens
        -Choice between images with or without capitons
        -Choice of number of cached files and expiry time for reload of new 
batches of random images
  
  Totally independent from the LMS server etc. No more versions or plugins 
conflicts, no more spinning
  disks on the NAS, heavy machinery required to rund 24/7 etc... ;-)
  
  This was my very first complete PHP-script ever, so sorry for the bad and 
ugly coding, without
  any error or exception handling. It barely does what it's supposed to do, but 
gets the jobb done
  for the time being, if you can get it to work. I'm on the forum from time to 
time, but don't have
  the resources to provide any reliable support. 
  
  Feel free to copy and improve as you feel fit! I certainly did a lot of 
copying from a lot of
  amazing resources and competent and sharing people on the web. Som much 
research and copying 
  that I don't remember the people I should be thanking.
  
  
  !! Anyways, a special thanks to the primus motors on the Squeezebox community 
forum who keeps both
  the best audio community and the best music server/player ecosystem ever 
still alive and kicking!!
  
  Nice also if any improvements to this script were posted back on the the 
forum!
  
  
  by vegz78... */
  
  
  //Global variables
  $LIST_SIZE = 60; //Number of random images to be processed and  included in 
the image URL list
  $FILE_AGE_MAX = 2500; //Time in minutes before a random image file pointed to 
in the list is changed
  $CAPTIONS = 1; //0 = Captions OFF, 1 = Captions ON
  $IMG_SOURCE = '/mnt/Some_path_to_images'; //Path to original large image 
files 
  
  $URL_ROOT = 'http://192.168.x.x/'; //Host server address
  $IMAGE_ROOT = 'sbtouch_img/'; //Storage folder for images in the www-directory
  
  
  //Identify player type and set corresponding identifier variable
  $isTouch = false;
  $FILE_NAME = 'sbradio.lst';
  $FILE_SUFFIX = '.jpg';
  if(isset($_SERVER['HTTP_USER_AGENT'])) { 
        $playerType = $_SERVER['HTTP_USER_AGENT']; //Identifier for the 
different player types
        if (strpos($playerType, 'fab4') !== false) {
                $isTouch = true; //TRUE if Squeezebox Touch, FALSE otherwise
                $FILE_NAME = 'sbtouch.lst'; //URL list file name for the Touch
                $FILE_SUFFIX = '_fab4.jpg'; //Image file suffix for the Touch
        }
  }
  
  
  //Check if the local optimized copies of files exist or must be created OR if 
they are too old and must be replaced with new images
  $fileArray = array();  //Array of files which should be updated or created
  for ($i = 1; $i <= $LIST_SIZE; $i++) {
        if (!file_exists("{$IMAGE_ROOT}{$i}{$FILE_SUFFIX}") || (time() - 
filemtime("{$IMAGE_ROOT}{$i}{$FILE_SUFFIX}"))/60 > $FILE_AGE_MAX) {
                $fileArray[] = $i;
        }
  }
  
  
  //Number of image and file operations until the images and the image URL list 
is ready
  $fileArraySize = count($fileArray);
  //echo "Array size = " . count($fileArray) . "!\n";
  
  
  //Start image and file operations if any images are missing or old
  if ($fileArraySize >=1) {
  
        //Traverse directory and subdirectories recursively and populate array 
with filenames
        $fileNameArray = array();
        $Directory = new RecursiveDirectoryIterator($IMG_SOURCE);
        $Iterator = new RecursiveIteratorIterator($Directory);
        $Regex = new RegexIterator($Iterator, '/^.+(.jpe?g)$/i', 
RecursiveRegexIterator::GET_MATCH);
  
        foreach($Regex as $name => $Regex) {
                $fileNameArray[] = $name;
  //            echo "$name\n";
        }
  
  
        //Shuffle the array, and extract and resize the needed number of random 
new image files
  //    echo count($fileNameArray) . "\n";
        shuffle($fileNameArray);
        for ($i = 0; $i <= $fileArraySize-1; $i++) {
  
                //Captions ON
                if ($CAPTIONS == 1) {
                        $exploded = explode("/", $fileNameArray[$i]);
                        $event = $exploded[count($exploded)-2]; //Makes parent 
directory available as string for caption text
                        $fileName = $exploded[count($exploded)-1];  //Makes 
file name available as string for caption text
                        if($isTouch) {
                                exec('/usr/bin/convert \\( ' . 
escapeshellarg($fileNameArray[$i]) . ' -auto-orient -background none -resize 
480x480 -gravity center -extent 480x272 \\) \\( -background \'#0005\' -fill 
white -gravity west -size 480x25 -pointsize 11 caption:' . 
escapeshellarg($fileName. "\n") . escapeshellarg($event) . ' \\) -gravity south 
-composite ' . escapeshellarg($IMAGE_ROOT) . escapeshellarg($fileArray[$i]) . 
escapeshellarg($FILE_SUFFIX));
                        }
                        else {
                                exec('/usr/bin/convert \\( ' . 
escapeshellarg($fileNameArray[$i]) . ' -auto-orient -background none -resize 
320x320 -gravity center -extent 320x240 \\) \\( -background \'#0005\' -fill 
white -gravity west -size 320x22 -pointsize 10 caption:' . 
escapeshellarg($fileName. "\n") . escapeshellarg($event) . ' \\) -gravity south 
-composite ' . escapeshellarg($IMAGE_ROOT) . escapeshellarg($fileArray[$i]) . 
escapeshellarg($FILE_SUFFIX));
                        }
                }
  
                //Captions OFF
                else {
                        if($isTouch) {
                                exec('/usr/bin/convert ' . 
escapeshellarg($fileNameArray[$i]) . ' -auto-orient -background none -resize 
480x480 -gravity center -extent 480x272 ' . escapeshellarg($IMAGE_ROOT) . 
escapeshellarg($fileArray[$i]) . escapeshellarg($FILE_SUFFIX));
                        }
                        else {
                                exec('/usr/bin/convert ' . 
escapeshellarg($fileNameArray[$i]) . ' -auto-orient -background none -resize 
320x320 -gravity center -extent 320x240 ' . escapeshellarg($IMAGE_ROOT) . 
escapeshellarg($fileArray[$i]) . escapeshellarg($FILE_SUFFIX));
                        }
                }
        }
  }
  
  
  //Update the file for the players with the URL list for the Image Viewer 
applet to read
  $indexList = array();
  for ($i = 1; $i <=  $LIST_SIZE; $i++) {
        $indexList[] = $i;
  }
  shuffle($indexList); //For random image viewer starts
  
  $fp = fopen($FILE_NAME, 'w');
  for ($i = 0; $i <=  $LIST_SIZE-1; $i++) {
        fwrite($fp, $URL_ROOT . $IMAGE_ROOT . $indexList[$i] . $FILE_SUFFIX 
."\n");
  }
  fclose($fp);
  
  
  //Send image URL file to Image Viewer
  readfile($FILE_NAME); 
  
  
  ?>
  
--------------------


+-------------------------------------------------------------------+
|Filename: Plug.gif                                                 |
|Download: http://forums.slimdevices.com/attachment.php?attachmentid=24289|
+-------------------------------------------------------------------+

------------------------------------------------------------------------
Vegz78's Profile: http://forums.slimdevices.com/member.php?userid=32897
View this thread: http://forums.slimdevices.com/showthread.php?t=108498

_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to