changeset 30:f2c21a8b9071

Sort images in a folder by their capture timestamp.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 23 Apr 2016 19:36:31 +0300
parents 8cf743c7ea23
children 300396947f04
files mgtool.php
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mgtool.php	Sun Apr 17 13:59:39 2016 +0300
+++ b/mgtool.php	Sat Apr 23 19:36:31 2016 +0300
@@ -327,6 +327,15 @@
 }
 
 
+function mgSortFunc($a, $b)
+{
+  if (isset($a["datetime"]) && isset($b["datetime"]))
+    return strcmp($b["datetime"], $a["datetime"]);
+  else
+    return 0;
+}
+
+
 function mgWriteGalleryCache($cacheFilename, &$gallery, &$entries, &$parentEntry)
 {
   // Store gallery cache for this directory
@@ -343,7 +352,8 @@
     else
       $albums[$ename] = &$edata;
   }
-  ksort($images);
+
+  uasort($images, "mgSortFunc");
   ksort($albums);
 
   // Choose gallery album image