aboutsummaryrefslogtreecommitdiff
path: root/img/json.php
diff options
context:
space:
mode:
Diffstat (limited to 'img/json.php')
-rwxr-xr-ximg/json.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/img/json.php b/img/json.php
new file mode 100755
index 0000000..1fff451
--- /dev/null
+++ b/img/json.php
@@ -0,0 +1,52 @@
+<?php
+$allimages = array();
+$imagetimes = array();
+header("Content-type: application/json; charset=utf-8");
+
+function test_image($name) { // Returns true if a file is an image, false otherwise
+ if(getimagesize($name)) {
+ return true;
+ }
+ return false;
+}
+
+function imagetime($file) { // This needs to return a Unix timestamp.
+ global $imagetimes;
+ if(!$imagetimes[$file]) {
+ $imagetimes[$file] = filemtime($file);
+ }
+ return $imagetimes[$file];
+}
+
+$images = array_filter(scandir("."), "test_image"); // Generate array of every image in the directory by filename
+
+usort($images, function($a, $b) { // Sort images by modification date of the files
+ return imagetime("$a") - imagetime("$b");
+});
+
+$pmt = "";
+foreach($images as $im) { // Loops through each image and echoes it to the page
+
+ $no = substr($im, 0, strpos($im, ".")); // Filename with extension stripped
+ $mt = date("Y-m-d", imagetime("$im")); // File modification date in ISO format
+ $is = getimagesize("$im");
+
+ $allimages[$im] = array(
+ "date" => imagetime("$im"),
+ "x" => $is[0],
+ "y" => $is[1],
+ "mime" => $is["mime"],
+ "alt" => ""
+ );
+
+ /*if($pmt != $mt) {
+ if($pmt != "") {
+ echo "</article>";
+ }
+ $pmt = $mt;
+ echo "<h2>$mt</h2><article class='imgs'>";*/
+ #}
+
+ #echo("<a class='img' href='/img/$im'><img src='/img/thumbs/$no.jpg'><span>$im >> $ist</span></a>");
+}
+echo(json_encode($allimages, JSON_PRETTY_PRINT)); \ No newline at end of file