aboutsummaryrefslogtreecommitdiff
path: root/img/json.php
blob: 1fff4510ceb12506da4d0c6c696417f135fca269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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));