Hi all
Does anyone have a very quick implementation of a jpg gallery web page for all images within a given directory?
I'm guessing that a periodic cron job to run a Python script (using PIL perhaps) to create the thumbnails may work, but I've no idea on the next steps in getting the resultant batch to display on a Web page: the quantity and file references would clearly be variable. The full size jpg would also need to be displayed on selection.
Any ideas?
-
- Posts: 128
- Joined: Sun Dec 23, 2012 9:44 pm
- DougieLawson
- Posts: 40781
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: Basic thumbnail gallery view
Warning, ugly PHP code alert!
You'll need to do something special to build the thumbnails, that ugly PHP program generates HTML wrapped round the full size images.
The basic principle is find the filename wrap <LI>... </LI> and <IMG SRC=....> tags round it.
Code: Select all
<?php function iterateDirectory($i)
{
echo '<ul>';
foreach ($i as $path) {
if ($path->isDir())
{
iterateDirectory($path);
}
else
{
if (strpos($path, '.jpg')) {
$output = array();
$chunks = explode('/', $path);
foreach ($chunks as $i => $chunk) {
array_push($output, $chunk);
}
echo '<li><img src=..'.join("/",$output).'></li>';
}
}
}
echo '</ul>';
}
# beware the hard coded directory name.
$dir = '/var/www/httpi/pics';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
iterateDirectory($iterator);
?>
The basic principle is find the filename wrap <LI>... </LI> and <IMG SRC=....> tags round it.
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.