Topic: Can juicebox update itself based on contents of image folder? [SOLVED]

Hello -

Juicebox seems to do everything we need, except for the ability automatically display (or not display) images as image files are either added or removed from the image directory.  I'm currently exploring the free version, so I don't know if this is already a feature of the paid, which is what I'll need should I use this script.

I found a thread that seems to have a solution for this,

http://juicebox.net/forum/viewtopic.php?id=91

but from my limited understanding of coding, this solution won't work on a linux based site, such as mine. 

So, does this already work in the paid version, and if not, is there another thread with a copy/paste solution for php that I can use?   I'm a photographer and not a coder, so it would be great if it would be that simple.

Thanks,
bw

Re: Can juicebox update itself based on contents of image folder? [SOLVED]

The solution you found in the forum thread you quoted should work fine on a Linux server (as long as PHP is installed) and will work with both Juicebox-Lite and Juicebox-Pro.
Just give it a try and it should work fine.
Also, now that Juicebox (since v1.4.3) scales the images used for the thumbnails (rather than center-cropping them), you could use a single folder of images for both the thumbnails and main images (without having to worry about creating a dedicated folder of thumbnail images).

3 (edited by billwill 2015-01-17 15:20:59)

Re: Can juicebox update itself based on contents of image folder? [SOLVED]

Thanks Steven -

I do have php on the server.  What do I do with this?  Add it to a config file?  Wrap it in php tags and put it somewhere? 


public class jbController : ApiController
    {
        // GET api/<controller>
        public HttpResponseMessage Get()
        {
            String s = "";
            s += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
            s += "<juiceboxgallery>";
            s += "<image imageURL=\"http://biltema.se/ProductImages/17/large/17-380_l.jpg\"";
            s += " thumbURL=\"\"";
            s += " linkURL=\"http://biltema.se/ProductImages/17/large/17-380_l.jpg\"";
            s += " linkTarget=\"_blank\"";
            s += " sourcePath=\"http://biltema.se/ProductImages/17/large/17-380_l.jpg\">";
            s += "<title></title>";
            s += "<caption></caption>";
            s += "</image>";
            s += "<image imageURL=\"http://biltema.se/ProductImages/25/large/25-0490_l.jpg\"";
            s += " thumbURL=\"\"";
            s += " linkURL=\"http://biltema.se/ProductImages/25/large/25-0490_l.jpg\"";
            s += " linkTarget=\"_blank\"";
            s += " sourcePath=\"http://biltema.se/ProductImages/25/large/25-0490_l.jpg\">";
            s += "<title></title>";
            s += "<caption></caption>";
            s += "</image>";
            s += "</juiceboxgallery>";

            return new HttpResponseMessage() { Content = new StringContent(s, Encoding.UTF8, "application/xml") };
        }
    }

Re: Can juicebox update itself based on contents of image folder? [SOLVED]

You're looking at the right forum thread but the wrong code. (The code you posted above is specific to a user's own test case using ASP.NET Web API.)
The code you should be using is in this forum post.
Put the following code in a file named 'config.php' and upload it to the same directory as the HTML page which contains your gallery's embedding code. Also in this directory, create a folder named 'images' and upload all your images there.

<?php
header("Content-type: application/xml");
function GetDirArray($folder)
{
    $handle=opendir($folder);
    while ($file=readdir($handle))
    {
        if ($file!="." && $file!="..")
        {
            $ret[count($ret)]=$file;
        }
    }
    closedir($handle);
    sort($ret);
    return $ret;
}
$gallery=GetDirArray('images');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<juiceboxgallery title="Juicebox Gallery">';
for ($i=0; $i<sizeof($gallery); $i++)
{
    echo '<image imageURL="images/'.$gallery[$i].'" thumbURL="images/'.$gallery[$i].'" linkURL="" linkTarget="">';
    echo '<title></title>';
    echo '<caption></caption>';
    echo '</image>';
}
echo '</juiceboxgallery>';
?>

Now add the following to your gallery's embedding code:

configUrl : 'config.php',

For example, your gallery's embedding code might look something like this:

<!--START JUICEBOX EMBED-->
<script src="jbcore/juicebox.js"></script>
<script>
    new juicebox({
        configUrl: "config.php",
        containerId : "juicebox-container",
        galleryWidth: "100%",
        galleryHeight: "100%",
        backgroundColor: "#222222"
    });
</script>
<div id="juicebox-container"></div>
<!--END JUICEBOX EMBED-->

Now, your gallery will display all images in the 'images' folder and each time you upload images to the 'images' folder, they will automatically be displayed in the gallery when the gallery is viewed.

5 (edited by billwill 2015-01-18 10:41:25)

Re: Can juicebox update itself based on contents of image folder? [SOLVED]

Wow.  Your reply really surprised me.   Providing the code AND step by step instructions.  Most developers would have stopped with the first sentence in your reply.

Thanks so much for both, not to mention how quickly you provided the answer.  It works great!

Re: Can juicebox update itself based on contents of image folder? [SOLVED]

You're welcome!
I'm glad you've got it working.
Thank you for posting back to let me know.