-
-
Save MaverickEsq/9494f4ee8325de4242415a99dca0dd89 to your computer and use it in GitHub Desktop.
Image gallery generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$startTime = microtime(); | |
# config | |
$dir = './'; // path to folder of images | |
$recursive = true; // scan all folders in selected path, recursively | |
$imageExtensions = array('jpg', 'png', 'gif', 'jpeg'); // the image types you want to display | |
$perPage = 16; // how many images to show per page (multiple of 4 recommended) | |
$showFileInfo = true; // display file information beneath the image | |
# variables | |
$imageList = array(); | |
$currentPage = isset($_GET['p']) ? (int)$_GET['p'] : 1; | |
# functions | |
function dateSort($a, $b) | |
{ | |
if ($a['created']==$b['created']) return 0; | |
return ($a['created'] > $b['created']) ? -1 : 1; | |
} | |
# get all images | |
if ($recursive) { | |
$iterator = new RecursiveDirectoryIterator($dir); | |
foreach ($iterator as $path => $info) { | |
$extension = explode('.', $path); | |
if (in_array(strtolower(array_pop($extension)), $imageExtensions)) { | |
$hash = md5($path); | |
$imageList[] = array('path' => $path, 'created' => filemtime($path), 'hash' => $hash); | |
} | |
} | |
} else { | |
if ($handle = opendir($dir)) { | |
while (false !== ($path = readdir($handle))) { | |
$extension = explode('.', $path); | |
if (in_array(strtolower(array_pop($extension)), $imageExtensions)) { | |
$hash = md5($path); | |
$imageList[$hash] = array('path' => $path, 'created' => filemtime($path), 'hash' => $hash); | |
} | |
} | |
closedir($handle); | |
} | |
} | |
# sort by newest | |
usort($imageList, 'dateSort'); | |
# get pagination calculations | |
$noImages = count($imageList); | |
$noPages = round($noImages/$perPage, 0, PHP_ROUND_HALF_UP); | |
$pageStart = ($currentPage-1)*$perPage; | |
$pageEnd = $pageStart+$perPage; | |
if ($pageEnd > $noImages) | |
$pageEnd = $noImages; | |
# display html | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Images</title> | |
<!-- Bootstrap --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/0.9.9/magnific-popup.css"> | |
<style type="text/css"> | |
.thumb { | |
display: block; | |
overflow: hidden; | |
height: 155px; | |
width: 250px; | |
} | |
.thumb img { | |
display: block; | |
min-width: 100%; | |
min-height: 100%; | |
-ms-interpolation-mode: bicubic; | |
} | |
body { | |
background: #2e2e2e; | |
} | |
p { | |
color: #797979 | |
} | |
.thumbnail { | |
background-color: #1d1d1d; | |
opacity: 95%; | |
border: 1px solid #1d1d1d; | |
} | |
strong { | |
color: #e5b567; | |
} | |
h1>a { | |
color: #e87d3e; | |
} | |
.pager li > a { | |
color: #b05279; | |
background-color: #1d1d1d !important; | |
border: 1px solid #1d1d1d | |
} | |
.disabled li > a { | |
color: #9e86c8; | |
} | |
.tags { | |
float: right; | |
margin-top: -1.5em; | |
margin-right: 3px; | |
margin-bottom: 3px; | |
} | |
</style> | |
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | |
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
<!--[if lt IE 9]> | |
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | |
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12 col-sm-12"> | |
<h1><a href="<?=basename($_SERVER["SCRIPT_FILENAME"], ".php")?>.php">Images</a></h1> | |
</div> | |
</div> | |
<?php if ($noPages > 1): ?> | |
<div class="row"> | |
<div class="col-md-12"> | |
<nav> | |
<ul class="pager"> | |
<li class="previous <?=$currentPage==1?'disabled':''?>"><a href="<?=basename($_SERVER["SCRIPT_FILENAME"], ".php")?>.php?p=<?=$currentPage-1?>"><span aria-hidden="true">←</span> Newer</a></li> | |
<li>Page <?=$currentPage?> / <?=$noPages?></li> | |
<li class="next <?=$currentPage==$noPages?'disabled':''?>"><a href="<?=basename($_SERVER["SCRIPT_FILENAME"], ".php")?>.php?p=<?=$currentPage+1?>">Older <span aria-hidden="true">→</span></a></li> | |
</ul> | |
</nav> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php | |
for ($i=$pageStart;$i<$pageEnd;$i++): | |
if (($i+1)%4==1) | |
echo '<div class="row">'; | |
?> | |
<div class="col-sm-2 col-md-3"> | |
<div class="thumbnail"> | |
<div class="thumb"> | |
<a href="<?=$imageList[$i]['path']?>" class="lightbox"> | |
<img src="<?=$imageList[$i]['path']?>" /> | |
</a> | |
</div> | |
<?php | |
if ($showFileInfo): | |
$imageSize = getimagesize($imageList[$i]['path']); | |
$fileSize = number_format(filesize($imageList[$i]['path'])); | |
$fileName = basename($imageList[$i]['path']); | |
?> | |
<div class="caption"> | |
<h5><strong><?=$fileName?></strong></h5> | |
<p><span class="glyphicon glyphicon-picture"></span> <?=$imageSize['mime']?></p> | |
<p><span class="glyphicon glyphicon-paperclip"></span> <?=$fileSize?> bytes</p> | |
<p><span class="glyphicon glyphicon-time"></span> <?=date('Y-m-d H:i:s', $imageList[$i]['created'])?></p> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> | |
<?php | |
if (($i+1)%4==0) | |
echo '</div>'; | |
endfor; | |
if ($i%4!=0) | |
echo '</div>'; | |
?> | |
<?php if ($noPages > 1): ?> | |
<div class="row"> | |
<div class="col-md-12"> | |
<nav> | |
<ul class="pager"> | |
<li class="previous <?=$currentPage==1?'disabled':''?>"><a href="<?=basename($_SERVER["SCRIPT_FILENAME"], ".php")?>.php?p=<?=$currentPage-1?>"><span aria-hidden="true">←</span> Newer</a></li> | |
<li>Page <?=$currentPage?> / <?=$noPages?></li> | |
<li class="next <?=$currentPage==$noPages?'disabled':''?>"><a href="<?=basename($_SERVER["SCRIPT_FILENAME"], ".php")?>.php?p=<?=$currentPage+1?>">Older <span aria-hidden="true">→</span></a></li> | |
</ul> | |
</nav> | |
</div> | |
</div> | |
<?php endif; ?> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> | |
<p class="text-center">I've found <strong><?=number_format($noImages, 0, '.', ' ')?></strong> images and loaded the page in <strong><?=microtime()-$startTime?></strong> seconds</p> | |
<div class="tags"> | |
<a href="https://faggotry.org"><img src="data:image/vnd.microsoft.icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAACAcAAAgHAAAAAAAAAAAAAAAAAAAAAAAAAAAAADm5uaJenp64D09PeNYWFjjz8/Psf7+/pX+/v5ZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC1tbWWJiYm9AAAAP8AAAD/AAAA/wUFBfQgICDVQUFB6aurq8b+/v46////CAAAAAAAAAAAAAAAAAAAAAD5+fkpNTU18wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8CAgL+QUFB6Y2Njez+/v5RAAAAAAAAAAAAAAAAx8fHlAYGBvsAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/mJiY0AAAAAAAAAAA////BqampskAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/09PT98AAAAAAAAAAP7+/hN+fn7QAAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP9ubm62AAAAAAAAAAD///8MaWlp6gAAAP8AAAD/AAAA/goKCvoAAAD/AAAA/wAAAP8AAAD/AgIC/AsLC/pOTk7t3t7eJgAAAAAAAAAAAAAAAMHBwWdsbGzoAAAA/wAAAP5HR0f+AwMD/AsLC/gU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eysrKvr6+tra2mpqakpKSZmZmVlZSHh4aJhoOBgYB+fX19fHx6eXh4d3ZycXBxcXBubWxtbGtmZmZiYV5eWFZdWFZXVlVQT01EREJEQ0ErRlI/QkFAPz0/Pzw+ODU4Ojk5OTg7ODczMzMwNDQyMjAwMTAuLy0pJyUiKStbAGoZAAAASXRSTlMAIiIzMzMzRERViIiZmZmqqru73d3d3d3d3e7u7u7/////////////////////////////////////////////////////////2AhnNAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABZ0RVh0Q3JlYXRpb24gVGltZQAwOS8xOC8yM9iukNQAAAAcdEVYdFNvZnR3YXJlAEFkb2JlIEZpcmV3b3JrcyBDUzbovLKMAAAAuElEQVQYlY3O2RqBUBSG4ZUhFELmtEvYmVXbsBuUIrr/KzLWsXX2vQf/swD+uuKgAlAZFDNoYhFAxM0M2ojkcgS1M+BPx9HoeOLTLkkTZTxWJlLpB52FsZtOt8ai+23mQeaW51lz8mA+kL9HSXy7xUl0L3xACCLn6rpXJwqEV7b6Z0p9Owxtn9JzrwW1JVI1bXbYzzRNRcs6AGeuMVpdLiuE1yb33mDL1aG+2ejDaplNX2Mbstz41hPE1RW1WhwsXQAAAABJRU5ErkJggg==" alt="racoon" title="original by fally.ro"></a> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed darkmode, removed admin mode, removed deletion, made some pretty tags, removed unneeded JS once admin mode was gone.