Created
January 12, 2015 12:54
-
-
Save pachacamac/2871db4a90695b1ad90f to your computer and use it in GitHub Desktop.
Simple drop in gallery in PHP with thumbnail support
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 | |
$files = preg_grep('/\.jpg$/i', glob('*')); | |
if($_GET['thumb'] && in_array($_GET['thumb'], $files)){ | |
$thumb = exif_thumbnail($_GET['thumb'], $width, $height, $type); | |
if($thumb !== false){ // show embedded thumbnail | |
header('Content-type: '.image_type_to_mime_type($type)); | |
echo $thumb; | |
}elseif(false){ | |
// TODO: create thumbnail on the fly with imagemagick if installed | |
}else{ // fallback: show original image | |
header('Location: '.htmlentities($_GET['thumb'])); | |
} | |
exit; | |
} | |
?> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title><? echo ucwords(basename(getcwd()))." - ".count($files)." images" ; ?></title> | |
<style type="text/css"> | |
* { margin: 0; padding: 0; box-sizing: border-box; } | |
body { background: #333F47; text-align: center; } | |
a { text-decoration: none; } | |
img { margin: 1em; height: 8em; box-shadow: 0px 0px 5px #111; } | |
img:hover { box-shadow: 0px 0px 5px #eee; } | |
</style> | |
</head> | |
<body> | |
<?php | |
foreach($files as $index => $file){ | |
$exif = exif_read_data($file); | |
$datetime = htmlentities($exif['DateTimeOriginal']); | |
$file = htmlentities($file); | |
echo "<a href='$file'><img src='?thumb=$file' alt='$file' title='$datetime'></a>"; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment