No description
- PHP 51.7%
- HTML 43.1%
- Shell 5.2%
| .gitignore | ||
| .rootdir | ||
| about.html | ||
| create_symlinks_in_subdirs.sh | ||
| favicon.ico | ||
| index.php | ||
| LICENSE | ||
| README.md | ||
| viewcounter.php | ||
| viewcounts.php | ||
egg (Extremely Generic Gallery)
Minimal PHP directory gallery. Drop an index.php into a folder tree and it will render:
- A folder navigation bar (subdirectories of the current directory)
- A thumbnail grid for images (
.jpg/.png/.gif) and videos (.mp4)
Thumbnails are generated on demand and cached in .thumb/ directories.
How it works
Per-directory gallery (index.php)
index.php always operates on the current working directory ($dir = '.'):
- Ensures
./.thumb/exists. - Scans the directory for:
- Subfolders (everything except
./..and.thumb) - Image files matching
*.png,*.jpg,*.gif - Video files matching
*.mp4
- Subfolders (everything except
- Generates missing thumbnails:
- Images: resizes to height 200px, preserves aspect ratio, and writes a JPEG thumbnail into
./.thumb/using the original filename (even if the source is PNG/GIF). - Videos: runs
ffmpegto create an H.264 MP4 “thumbnail video” at./.thumb/<basename>.mp4(scaled to 200px height, faststart enabled).
- Images: resizes to height 200px, preserves aspect ratio, and writes a JPEG thumbnail into
Render mode is controlled by the presence of ./.rootdir:
- Root directory mode (
.rootdirexists):- Shows
AboutandViewcountslinks. - Does not auto-list the current directory’s media.
- Instead renders a shuffled, manually curated list of image paths (hardcoded array).
- Uses thumbnails located at
<image-dir>/.thumb/<filename>.
- Shows
- Sub directory mode (no
.rootdir):- Shows a “Return” link (
..). - Renders videos first (as autoplaying muted looping
<video>previews from./.thumb/*.mp4), then images. - Images use
./.thumb/<filename>if it exists, otherwise one will be generated.
- Shows a “Return” link (
View counting (viewcounter.php + viewcounts.php)
viewcounter.php is an image/video proxy that also increments counters in a SQLite DB:
- Derives the requested path from
$_SERVER['REQUEST_URI'](query string stripped). - Refuses missing files (404), otherwise serves the file with
mime_content_type()andreadfile(). - Uses
viewcounts.sqliteand two tables:views(image_url, count)whereimage_urlis UNIQUE (used withON CONFLICT(image_url) DO UPDATE).crawlers(count)single-row total.
- Skips counting thumbnails (
/.thumb/paths) and attempts to detect crawlers via a User-Agent regex; crawlers incrementcrawlersinstead ofviews.
viewcounts.php renders a “top N” page:
- Queries the
viewstable ordered bycountdescending (default limit 50). - Builds thumbnail URLs as
<dirname(image_url)>/.thumb/<basename(image_url)>and overlays the count.
Utility script
create_symlinks_in_subdirs.sh:
- Recursively renames directories by replacing spaces and hyphens with underscores (can be disabled in the script).
- Creates an
index.phpsymlink in every subdirectory (excluding.thumb) pointing back to the top-levelindex.php. - Applies ownership/permissions suitable for a typical
www-dataweb root. - This script must be ran manually when a new subfolder is created.
Requirements
- PHP with:
- GD (image thumbnail generation)
- PDO SQLite (view counter)
ffmpegin PATH (MP4 thumbnail generation)