Topic: Sorting options for galleries?

Are there any additional sorting options for images in galleries, other than by file name and file modification date?  For example, is there a way to sort by file creation (image capture) date, which would be useful in sorting images from more than one camera?  Or a way to sort using the sort order from another app, like Adobe Bridge (which creates an xml file showing sort order, ".BridgeSort")?

I often update a gallery after making changes to images and IPTC captions, but resorting a lot of photos manually is tedious.  Of course, I could just open up the existing gallery and make changes there, but I want to make the changes in the original directory where the photos reside, not in the JB gallery files, which have downsized/compressed images.  Also, I could manually replace images and thumbnails and revise the config.xml and index.html files, but that's impractical for large galleries.

Any suggestions?
Thanks!
Patrick

Re: Sorting options for galleries?

The only sorting options available within the JuiceboxBuilder-Pro interface are 'By File Name', 'By File Date' and 'Reverse' (from the 'Images -> Sort' drop-down menu at the top) and the ability to drag and drop a thumbnail (or a Ctrl+Click or Shift+Click selection of thumbnails) into a new position on the 'Images' tab.
There are no other automated methods of sorting images within a  gallery.

It would be possible to sort image's dynamically using a server-side scripting language such as PHP (no matter what order the images actually are in the gallery's XML file) but it would likely involve a lot of work to create such a script and knowledge of PHP would be required.
You would load the PHP script using a configUrl in your gallery's embedding code.
The script would then read the gallery's own static XML file, store the image tag data in an array, sort the array into whatever order you require (assuming that the property that the sorting relies on is available within PHP) and then output a new XML file on-the-fly.
This would be further complicated by the need to ensure that all associated thumbURL, linkURL, linkTarget, <title> and <caption> entries are still attached to their respective images.
It might also not be quite as fast as loading a gallery with a static XML file (especially in a gallery with a large number of images) but it might be an avenue you wish to pursue further.

Re: Sorting options for galleries?

I don't know whether this will help the poster, but for what it's worth...

I use two products (and which one depends on exactly what I'm doing)  in the course of getting photos from my camera to my PC:

1) jhead, free, http://www.sentex.net/~mwandel/jhead/
2) Downloader Pro, pretty cheap, http://breezesys.com/Downloader/index.htm

Among other things, these two pieces of software allow you to automatically name photos based on the image-capture date/time in the EXIF info, either during actual download or after the fact. I generally don't bother, but you can also append a string. I imagine there are other apps that perform similar duties, especially in the non-free category, on both PCs and other operating systems.

Thus, my images get named 2014-09-04-14-59-59.jpg, for instance. If I'm downloading from another camera and I happened to have taken another picture at the same second (doesn't really happen), it would get a (2) or A or something right before the period. Adding a string option would yield something like 2014-09-04-14-59-59-such-and-such-project.jpg.

The point is, if you (re)name pics based on when they were taken, software that later sorts only by file title will also have your pics sorted by image-capture time.

I don't mean to insult anyone if this info is not applicable in your particular case, or if you already knew about this sort of thing, etc.

Cheers,

Bill

Re: Sorting options for galleries?

Bill and Steven:

Thanks for the replies.  Bill, those are good suggestions.  Lightroom and other software will also rename files, and I do that, but I don't use a convention that would allow me to sort by file creation date.  The approach I use has worked for me for years (in part because other software allows me to sort by file creation date), so I'll probably stick with my old file naming method.  But I appreciate the suggestion.

I'll probably just write a perl script or something to read my .BridgeSort file and use that to reorder the image listing in the config.xml file. 

Steven, the ability to sort by file creation (capture) date seems like an obvious feature to add.

-Patrick

Re: Sorting options for galleries?

@wspollack

Thank you for your input. Any information which might help is appreciated.

@patrick7

With regard to my original suggestion of creating a gallery with JuiceboxBuilder-Pro and then doing the sorting dynamically via PHP when the gallery is displayed (rather than when it is created), here is an example which will display the images in the order in which they were taken (comparing the EXIF 'DateTimeOriginal' values for each image) from earliest to latest.

(1) In your gallery's embedding code, use a configUrl to point to a PHP file named 'sort.php':

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

(2) Create the PHP file named 'sort.php' with the following code:

<?php
header('Content-Type: application/xml');
$xml = simplexml_load_file('config.xml');
$arr = array();
foreach($xml->image as $img) {
    $arr[] = $img;
}
usort($arr, function($a, $b) {
    $a_exif_data = @exif_read_data($a->attributes()->imageURL);
    $b_exif_data = @exif_read_data($b->attributes()->imageURL);
    $a_exif_date = !empty($a_exif_data['DateTimeOriginal']) ? strtotime($a_exif_data['DateTimeOriginal']) : '';
    $b_exif_date = !empty($b_exif_data['DateTimeOriginal']) ? strtotime($b_exif_data['DateTimeOriginal']) : '';
    return $a_exif_date - $b_exif_date;
});
$dom_doc = new DOMDocument('1.0', 'UTF-8');
$dom_doc->formatOutput = true;
$settings_tag = $dom_doc->createElement('juiceboxgallery');
foreach ($xml->attributes() as $key=>$value) {
    $settings_tag->setAttribute($key, $value);
}
foreach($arr as $img) {
    $image_element = $dom_doc->createElement('image');
    foreach($img->attributes() as $key=>$value) {
        $image_element->setAttribute($key, $value);
    }
    $title_element = $dom_doc->createElement('title');
    $title_text = $dom_doc->createCDATASection($img->title);
    $title_element->appendChild($title_text);
    $image_element->appendChild($title_element);
    $caption_element = $dom_doc->createElement('caption');
    $caption_text = $dom_doc->createCDATASection($img->caption);
    $caption_element->appendChild($caption_text);
    $image_element->appendChild($caption_element);
    $settings_tag->appendChild($image_element);
}
$dom_doc->appendChild($settings_tag);
echo $dom_doc->saveXML();
?>

(3) Place the 'sort.php' file in your gallery folder (in the same directory as the gallery's 'config.xml' file).

This solution relies on the images in the gallery's 'images' folder having EXIF info.
Please note that JuiceboxBuilder-Pro strips EXIF info when resizing images so, if you are using JuiceboxBuilder-Pro to create your gallery, you may need to resize your images in an imaging program such as Adobe Photoshop (and ensure that the EXIF info is retained when saving them) before feeding them to JuiceboxBuilder-Pro and then deselect the 'Resize Images' checkbox (on the 'Images' tab) so that JuiceboxBuilder-Pro just copies the images (with EXIF info intact) into the gallery's 'images' folder.

I hope this helps.

Steven, the ability to sort by file creation (capture) date seems like an obvious feature to add.

Thank you for posting your suggestion in the Feature Requests thread. (It keeps all the suggestions together and ensures that they are not overlooked.)

Re: Sorting options for galleries?

Steven:

Thanks very much -- this is very helpful.

I'll probably stick with the approach of writing a script to read the .BridgeSort file and use the image order there to reorder the image lists in the config.xml file and the <noscript> section of index.html.  That will allow me to keep the resizing option and to use custom sorts and preserve them if I redo a gallery.

Just out of curiosity, does the sort.php approach slow things up noticeable for big galleries of (say, 100+) images? 

-Patrick

Re: Sorting options for galleries?

Just out of curiosity, does the sort.php approach slow things up noticeable for big galleries of (say, 100+) images?

No, it should not noticeably slow down the loading of a gallery.
I have just run a test using a gallery of 100 images.
I created 3 scenarios:
(1) A standard gallery with a static XML file.
(2) The same gallery but using the 'sort.php' file above (using EXIF info to sort the images).
(3) The same gallery but using the 'sort.php' file with a different sorting algorithm (using just the file name from the static XML file rather than having to extract EXIF info from the images themselves).
All three galleries loaded in pretty much the same time. There was very little difference between the three of them. (In fact, on clearing my browser's cache and reloading the galleries, there as no clear winner in terms of the fastest gallery to load the first image.)