No description
  • PHP 51.7%
  • HTML 43.1%
  • Shell 5.2%
Find a file
2026-02-19 12:52:26 +01:00
.gitignore Initial commit 2026-02-19 10:55:05 +01:00
.rootdir Initial commit 2026-02-19 10:55:05 +01:00
about.html change zip file link to git repo 2026-02-19 11:21:16 +01:00
create_symlinks_in_subdirs.sh Initial commit 2026-02-19 10:55:05 +01:00
favicon.ico Initial commit 2026-02-19 10:55:05 +01:00
index.php Exclude .git from folders 2026-02-19 12:52:26 +01:00
LICENSE add license 2026-02-19 11:21:30 +01:00
README.md readme update 2026-02-19 11:16:40 +01:00
viewcounter.php Initial commit 2026-02-19 10:55:05 +01:00
viewcounts.php Initial commit 2026-02-19 10:55:05 +01:00

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

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
  • 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 ffmpeg to create an H.264 MP4 “thumbnail video” at ./.thumb/<basename>.mp4 (scaled to 200px height, faststart enabled).

Render mode is controlled by the presence of ./.rootdir:

  • Root directory mode (.rootdir exists):
    • Shows About and Viewcounts links.
    • Does not auto-list the current directorys media.
    • Instead renders a shuffled, manually curated list of image paths (hardcoded array).
    • Uses thumbnails located at <image-dir>/.thumb/<filename>.
  • 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.

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() and readfile().
  • Uses viewcounts.sqlite and two tables:
    • views(image_url, count) where image_url is UNIQUE (used with ON 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 increment crawlers instead of views.

viewcounts.php renders a “top N” page:

  • Queries the views table ordered by count descending (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.php symlink in every subdirectory (excluding .thumb) pointing back to the top-level index.php.
  • Applies ownership/permissions suitable for a typical www-data web root.
  • This script must be ran manually when a new subfolder is created.

Requirements

  • PHP with:
    • GD (image thumbnail generation)
    • PDO SQLite (view counter)
  • ffmpeg in PATH (MP4 thumbnail generation)