Skip to content

Instantly share code, notes, and snippets.

@paxperscientiam
Last active April 7, 2016 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paxperscientiam/56ba0848da18fa5cc1ef to your computer and use it in GitHub Desktop.
Save paxperscientiam/56ba0848da18fa5cc1ef to your computer and use it in GitHub Desktop.
JSON manifest of HTML <img/> "src" and "alt" atributes
<?PHP function fileListJSON($small,$big,$outJSON) {
$outJSON = $outJSON;
// Sort the files alphanumerically, naturally. (thumbs)
if ($handle = opendir($small)) {
$files = array();
while ($files[] = readdir($handle));
sort($files,SORT_NATURAL);
closedir($handle);
}
$allowed = array('png');
$count = 0;
array_shift($files);
foreach ($files as $file) {
$info = new SplFileInfo($file);
$ext = pathinfo($info->getFilename(), PATHINFO_EXTENSION);
if (in_array($ext, $allowed)) {
$filepath = "image.php?f=un-flags/base64/" . $file;
$filepathbig = "image.php?f=un-flags/" . $file;
$jsonData[] = array("img" => $filepath,
"big" => $filepathbig,
"alt" => $file
);
}
}
$jsonData = array("items" => $jsonData);
$jsonData = json_encode($jsonData,JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
file_put_contents($outJSON . "images.json", $jsonData);
}
// Local Variables:
// firestarter: "gist -u 56ba0848da18fa5cc1ef %p"
// End:
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment