diff options
| author | Ada Isopods <me@bathynomus.xyz> | 2026-10-21 23:29:29 -0600 |
|---|---|---|
| committer | Ada Isopods <me@bathynomus.xyz> | 2026-10-21 23:30:36 -0600 |
| commit | 2ac93c5be73455a9f9ea3d53b300385078f9008b (patch) | |
| tree | c06ad45be3246fc6fe862228e1a407d0d3734db5 /img | |
| parent | c588388e1a66c326a30de15dded84a80ddbab67a (diff) | |
Diffstat (limited to 'img')
| -rwxr-xr-x | img/index.php | 66 | ||||
| -rwxr-xr-x | img/json.php | 52 |
2 files changed, 84 insertions, 34 deletions
diff --git a/img/index.php b/img/index.php index 7b4f61b..0240275 100755 --- a/img/index.php +++ b/img/index.php @@ -5,7 +5,11 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>/log/img</title> <link href="../style.css" rel="stylesheet" type="text/css" media="all"> - <?php include("../seasonal.php"); ?> + <?php include("../seasonal.php"); + + ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL);?> <style> .dir { padding: 1rem; @@ -19,6 +23,7 @@ a.img { display: flex; flex-direction: column; + word-break: break-word; } a.img :is(img, span) { margin: 1rem; @@ -36,45 +41,38 @@ <p>$ ls -t</p> <section class="dir"> <?php - $imagetimes = Array(); + $fp = "/var/www/data/deeptwisty/images.json"; + $images = json_decode(file_get_contents($fp)); + $pmt = ""; + $op = ""; + foreach($images as $if=>$im) { // Loops through each image and echoes it to the page - function test_image($name) { // Returns true if a file is an image (png or gif), false otherwise - return (strpos($name, ".png") > 0 or strpos($name, ".gif") > 0 or strpos($name, ".jxl") > 0); - } + $no = substr($if, 0, strpos($if, ".")); // Filename with extension stripped + $mt = date("Y-m-d", $im->date); // File modification date in ISO format + $ist = $im->x . "×" . $im->y; // Image size formatted as X×Ypx + + $dc = false; + if($pmt != $mt) { $dc = true; }// date change - function imagetime($file) { // This needs to return a Unix timestamp. - global $imagetimes; - if(!$imagetimes[$file]) { - $imagetimes[$file] = filemtime($file); + /*if($pmt != $mt) { + $pmt = $mt; + $op = "<h2>$mt</h2><article class='imgs'>".$op; + if($pmt != "") { + $op = "</article>".$op; } - 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("$b") - imagetime("$a"); - }); + }*/ - $pmt = ""; - foreach($images as $im) { // Loops through each image and echoes it to the page + if($dc and $pmt) { $op = "<h2>$pmt</h2><article class='imgs'>".$op; } + if($dc) { $op = "</article>".$op; } + $op = "<a class='img' href='/img/$if'><img src='/img/thumbs/$no.jpg' alt='$im->alt'><span>$if >> $ist</span></a>".$op; + - $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"); - $ist = $is[0] . "×" . $is[1]; // Image size formatted as X×Ypx - - 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>"); + if($dc) { + $pmt = $mt; } - ?> + } + echo "<h2>$pmt</h2><article class='imgs'>".$op; + ?> </section> <p>$</p> </body> 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 |
