Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SammysHP committed Aug 15, 2012
0 parents commit 3520f50
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.php
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Simple Image Browser
=============

Written with the goal of a simple php image gallery that does not require a database or JavaScript.

![Screenshot](http://i.imgur.com/49rK7.png)

This script scans the configured directories for images (jpeg, jpg, png, gif) and shows them one by one with a thumbnail navigation. You can create several albums. Please note that no thumbnails are created, but the original images are resized by the browser. This script is intended to be used with images of 800x800px max. Larger images will be resized by the browser (with proportions preserved).

Requirements
------------

* php

Installation & Configuration
----------------------------

* Copy `config.php.skel` to `config.php`. Options are explained in the configuration file.
* Upload everything contained in this repository (except raw, which are the original Photoshop files) to your webspace.
Binary file added arrow-left-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arrow-left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arrow-right-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arrow-right-tiny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added arrow-right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions config.php.skel
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* If true, this script tries to find all directories in "autodetectroot".
* (See next option "autodetectroot".)
*
* WARNING: Not yet implemented!
*
* Values: true, false
*/
$config['autodetect'] = false;


/**
* Root directory that is scanned with "autodetect" enabled.
*
* Values: relative path
*/
$config['autodetectroot'] = 'images';


/**
* Albums with manual configuration. This array is used if "autodetect" is
* false.
*
* Values: associative array with "Title" => "relative path"
*/
$config['albums'] = array(
'Home' => 'images'
);


/**
* The base title of this site. Image titles are appended with
* " :: image title".
*
* Values: string
*/
$config['sitetitle'] = 'Simple Image Browser';


/**
* Number of thumbnails next to the image. A value of n*3 looks best.
* Do not use high numbers because all images are loaded by the client (no
* thumbnail generation).
*
* Values: integer, 1-n
*/
$config['paginginterval'] = 9;


/**
* Sort images descending instead of ascending. Sorting is always alphabetically
* at the moment. Choose a good filename if you want any special sorting.
*
* Values: true, false
*/
$config['sortDescending'] = true;


/**
* URL for the home button next to the image. If empty, the button is hidden.
*
* Values: string
*/
$config['homeurl'] = '';


/**
* Text for the info/about page.
*
* Values: string, here with Nowdoc syntax
*/
$config['info'] = <<<'EOD'
<p>
Displayed with <a href="https://github.com/SammysHP/SimpleImageBrowser">Simple Image Browser</a> by <a href="http://www.sammyshp.de/">Sven Karsten Greiner</a>.
</p>
EOD;
Binary file added home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
169 changes: 169 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/*
* Copyright (C) 2012 Sven Karsten Greiner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

error_reporting(0);

include('config.php');

function generateImageUrl($album, $image) {
return '?album=' . rawurlencode($album) . '&amp;image=' . rawurlencode($image);
}

if (isset($_POST['album'])) {
header('Location: ?album=' . rawurlencode($_POST['album']));
die();
}

$directories = $config['albums'];
$random = false;

$album = $_GET['album'];
$image = $_GET['image'];

// Random image if no album and no image given or $_GET['random']
if (isset($_GET['random']) || ($album == null && $image == null)) {
$random = true;
}

// Validate given album or use first or random one
if ($album == null || !array_key_exists($album, $directories)) {
if ($random) {
$album = array_rand($directories);
} else {
reset($directories);
$album = key($directories);
}
}

// Scan directory for image files
$files = scandir($directories[$album], $config['sortDescending'] ? 1 : 0);
$images = array();
foreach ($files as $file) {
$f = strtolower($file);
if (!is_dir($directories[$album] . '/' . $file)
|| strstr($f, ".jpg")
|| strstr($f, ".jpeg")
|| strstr($f, ".png")
|| strstr($f, ".gif")) {
$images[] = $file;
}
}

// Validate given image or use first or random one in album
if ($image == null || !in_array($image, $images)) {
if ($random) {
$image = $images[array_rand($images)];
} else {
$image = $images[0];
}
}

// Calculate paging boundaries
$currentIndex = array_search($image, $images);
$pagingStart = floor($currentIndex / $config['paginginterval']) * $config['paginginterval'];
$neighbors = array_slice($images, $pagingStart, $config['paginginterval']);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $config['sitetitle'] . ((!isset($_GET['info'])) ? (' :: ' . htmlspecialchars($image)) : ' :: Info'); ?></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
if (isset($_GET['info'])) {
echo '<div id="infobox"><a href="./" title="Home" class="home"><img src="home.png" /></a>' . $config['info'] . '</div>';
} else {
?>
<table border="0" cellspacing="0" cellpadding="0" id="sitecontainer">
<tr>
<td>
<div id="sidebar">
<form action="" method="post" id="albumnav">
<input type="submit" name="albumselect" value="" />
<div class="select">
<select name="album" type="text" size="1" onchange="this.form.submit()">
<?php
foreach ($directories as $dir => $path) {
$selected = ($dir == $album) ? 'selected="selected"' : '';
$dir = htmlspecialchars($dir);
echo "<option $selected>$dir</option>";
}
?>
</select>
</div>
</form>
<div id="thumbnav">
<?php
foreach ($neighbors as $neighbor) {
$href = generateImageUrl($album, $neighbor);
$src = $directories[$album] . '/' . $neighbor;
$current = ($image == $neighbor) ? 'class="current"' : '';
echo "<a href=\"$href\"><img src=\"$src\" $current/></a>";
}
?>
</div>
<div id="thumbnav-paging">
<?php
if ($pagingStart > 0) {
$href = generateImageUrl($album, $images[$pagingStart - 1]);
echo "<a href=\"$href\" class=\"back\"><img src=\"arrow-left.png\" /></a>";
}
if ($pagingStart + $config['paginginterval'] < count($images)) {
$href = generateImageUrl($album, $images[$pagingStart + $config['paginginterval']]);
echo "<a href=\"$href\" class=\"next\"><img src=\"arrow-right.png\" /></a>";
}
$no = floor($currentIndex / $config['paginginterval']) + 1;
$of = floor(count($images) / $config['paginginterval']) + 1;
echo "<div>$no / $of</div>";
?>
</div>
<div id="info">
<a href="?random" title="Random"><img src="random.png" /></a>
<?php
if ($config['homeurl'] != "") {
echo '<a href="' . $config['homeurl'] . '" title="Home"><img src="home.png" /></a>';
}
?>
<a href="?info" title="Info"><img src="info.png" /></a>
</div>
</div>
</td>
<td id="imagecontainer">
<div style="position: relative;">
<?php
if ($currentIndex > 0) {
$href = generateImageUrl($album, $images[$currentIndex - 1]);
echo "<a href=\"$href\" class=\"navi back\"></a>";
}
if ($currentIndex + 1 < count($images)) {
$href = generateImageUrl($album, $images[$currentIndex + 1]);
echo "<a href=\"$href\" class=\"navi next\"></a>";
}
?>
<img src="<?php echo $directories[$album] . '/' . $image; ?>" />
</div>
</td>
</tr>
</table>
<?php
}
?>
</body>
Binary file added info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added random.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raw/arrow.psd
Binary file not shown.
Binary file added raw/home.psd
Binary file not shown.
Binary file added raw/info.psd
Binary file not shown.
Binary file added raw/random.psd
Binary file not shown.
Loading

0 comments on commit 3520f50

Please sign in to comment.