Created
June 4, 2018 14:47
-
-
Save bazooka07/026e98499e196ca727ca6602276be66f to your computer and use it in GitHub Desktop.
Build your pictures gallery ( https://kazimentou.fr/divers/gallery/ )
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
Options +Indexes | |
IndexOptions HTMLTable Charset=UTF-8 NameWidth=* DescriptionWidth=* | |
AddDescription "Les trois grâces" p1120276.jpg | |
AddDescription "Coucou, c'est nous !'" p1120283.jpg | |
AddDescription "L'homme de fer" p1120285.jpg | |
AddDescription "Ça grimpe !" p1260042.jpg | |
AddDescription "Place de l'Obélisque" p2030071.jpg | |
AddDescription "Émetteur radio" p3030099.jpg | |
AddDescription "Le Rhône à Andance" p4070117.jpg | |
AddDescription "Livaison de charbon" p5190145.jpg | |
AddDescription "Le pont qui menait à l'usine" pb030263.jpg | |
AddDescription "Friche industrielle" pb030264.jpg |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Galerie d'images</title> | |
<style> | |
body { margin:0; padding: 0; background: #eee; text-align: center; } | |
#gallery { display: flex; justify-content: space-around; flex-wrap: wrap; } | |
figure { border: 2px; background: #222; display: inline-block; padding: 0.8rem; border-radius: 1rem; margin: 0.5rem 0; } | |
figcaption { text-align: center; background: #fff; margin: 0.3rem 5%; padding: 0.3rem 0; } | |
</style> | |
</head><body> | |
<div id="gallery"> | |
<?php | |
/* | |
* Dans le dossier des images, faire | |
* $> ls *.jpg | sed -r 's/^(.*)$/AddDescription "" \1/' > .htaccess | |
* et compléter .htaccess avec la description des images. | |
* | |
* mogrify -strip -resize x400\> -quality 80% -path img/ *.jpg | |
* */ | |
const FOLDER = 'demo-gallery/img/'; // must end with '/' | |
const MASK1 = '@^.*/([^/]*)\.(?:jpe?g|png|gif)$@'; | |
const MASK2 = '@^AddDescription\s+"([^"]*)"\s+(.*)$@m'; | |
$photosList = glob(FOLDER.'*.{jpg,jpeg,png,gif}', GLOB_BRACE); | |
$filename = FOLDER.'.htaccess'; | |
if( | |
file_exists($filename) and | |
preg_match_all(MASK2, file_get_contents($filename), $matches, PREG_SET_ORDER) | |
) { | |
$description = array(); | |
foreach($matches as $m) { | |
$description[$m[2]] = $m[1]; | |
} | |
echo "<!--\n".print_r($description, true)."-->\n"; | |
} else { | |
echo "<p>$filename not found</p>"; | |
} | |
foreach($photosList as $photo) { | |
$name = basename($photo); | |
$caption = (!empty($description) and array_key_exists($name, $description)) ? $description[$name] : preg_replace(MASK1, '\1', $photo); | |
$imgSize = getimagesize($photo); | |
echo <<< FIGURE | |
<figure> | |
<img src="$photo" {$imgSize[3]} alt="$caption" /> | |
<figcaption>$caption</figcaption> | |
</figure>\n | |
FIGURE; | |
} | |
?> | |
</div> | |
<p><a href="<?php echo FOLDER; ?>">Voir le dossier</a></p> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment