Skip to content

Generates a static site photo gallery from a folder of images. Генерирует статический сайт фото-галерею из папки с изображениями

License

Notifications You must be signed in to change notification settings

Hyacinth55/Static_PhotoSite_Gallery

Repository files navigation

Repository contents

  • generate_gallery.py — site generation script (image conversion, HTML generation, assets).
  • add_cookie_banner.py — script to add cookie consent banner and create privacy.html, and to patch HTML (deferred Google Fonts loading).
  • generate_gallery.exe — Windows executable equivalent to generate_gallery.py (in the ZIP next to source files).
  • add_cookie_banner.exe — Windows executable equivalent to add_cookie_banner.py (in the ZIP next to source files).
  • config.json — configuration file (example below). For convenience, you can rename config_example.json in the repository.
  • site_structure — example folder structure you must create and populate before running.
  • LICENSE — MIT

Important: the output folder will be created automatically if it does not exist.

Special note

  • The cookie consent banner for Google Fonts is required. The add_cookie_banner.py script defers Google Fonts loading and performs it only after the user explicitly accepts. This is necessary to avoid automatic requests to third-party services before user consent.

Requirements (if you run the Python sources)

  • Python 3.7+
  • Python packages:
    • Pillow — image processing
    • Jinja2 — template rendering
    • tqdm — (recommended for progress indicator) Install with:
pip install pillow jinja2 tqdm

If you use the .exe builds (generate_gallery.exe and add_cookie_banner.exe), no extra installation is required — run the exe directly.
Attention — precompiled .exe files

  • This repository includes two precompiled Windows executables: generate_gallery.exe and add_cookie_banner.exe. These binaries were built from the repository sources and verified by the author — they do not contain malware. Some antivirus products and Windows SmartScreen may still flag unsigned PyInstaller binaries as threats. If you see a warning, you can:
    1. Run the scripts from source instead: python generate_gallery.py and python add_cookie_banner.py; or
    2. If you trust the files, click “More info” → “Run anyway” in the SmartScreen dialog, or restore the file from quarantine and add an exclusion in Windows Defender.

Environment variable

  • To specify an alternative path to config.json, set the environment variable GALLERY_CONFIG, for example:
    • Windows (cmd): set GALLERY_CONFIG=C:\path\to\config.json
    • PowerShell: $env:GALLERY_CONFIG = 'C:\path\to\config.json'
    • Linux/macOS: export GALLERY_CONFIG=/path/to/config.json

Configuration — config.json Below is an example config.json. Replace paths and parameters with your own values.

{
  "GALLERY_DIR": "C:/Users/xxx/Documents/Site/",
  "IMAGES_DIR": "C:/Users/xxx/Documents/Site/images",
  "MAIN_DIR": "C:/Users/xxx/Documents/Site/main",
  "OUTPUT_DIR": "C:/Users/xxx/Documents/Site/output",
  "FAVICON_SRC_DIR": "C:/Users/xxx/Documents/Site/favicon",

  "THUMB_SIZE": [400, 300],
  "MAIN_THUMB_SIZE": [400, 300],
  "THUMB_QUALITY": 80,
  "MAIN_THUMB_QUALITY": 80,
  "FULL_QUALITY": 85,

  "COLUMNS": 3,
  "ROWS": 10,
  "PER_PAGE": null,

  "TITLE": "your_domain_name",
  "TITLE_FONT_FAMILY": "Merriweather, Georgia, 'Times New Roman', serif",
  "TITLE_FONT_SIZE_PX": 36,
  "TITLE_FONT_COLOR": "#5B3A29",

  "MENU_FONT_FAMILY": "Roboto, Arial, Helvetica, sans-serif",
  "MENU_FONT_SIZE_PX": 24,
  "MENU_FONT_COLOR": "#5B3A29",

  "SUBMENU_FONT_FAMILY": "Roboto, Arial, Helvetica, sans-serif",
  "SUBMENU_FONT_SIZE_PX": 20,
  "SUBMENU_FONT_COLOR": "#5B3A29",
  "SUBMENU_MIN_WIDTH_PX": 260,

  "MAIN_TEXT_FONT_FAMILY": "Roboto, Arial, Helvetica, sans-serif",
  "MAIN_TEXT_FONT_SIZE_PX": 18,
  "MAIN_TEXT_FONT_COLOR": "#111111",

  "MAIN_COUNT": 4,
  "FORCE_RECREATE": true,
  "CLEAN_NON_WEBP": false,

  "FULL_CROP": true,
  "FULL_LONG_SIDE_PX": 800,

  "BAGUETTE_CSS_URL": "https://unpkg.com/baguettebox.js@1.11.1/dist/baguetteBox.min.css",
  "BAGUETTE_JS_URL": "https://unpkg.com/baguettebox.js@1.11.1/dist/baguetteBox.min.js"
}

Field descriptions (what each field controls)

  • GALLERY_DIR — base project folder (optional root; usually not necessary to change).
  • IMAGES_DIR — folder with source images. MUST contain image files with extensions .jpg, .jpeg, or .png. The script walks this folder recursively; subfolders become gallery sections.
  • MAIN_DIR — folder with main content. REQUIRED contents:
    • text.txt — main page text (paragraphs separated by blank lines).
    • banner.txt — text for the cookie consent banner (replaces default banner text).
    • at least one image file (.jpg, .jpeg, or .png) — the first found image will be used as the site logo and copied to output/assets/logo/.
  • OUTPUT_DIR — target directory for the generated site. If it doesn’t exist, it will be created automatically. The script will create subfolders inside (photos, thumbs, etc.).
  • FAVICON_SRC_DIR — folder containing a favicon file (.ico, .png, .jpg, .jpeg). The first found file will be copied to output/favicon/ and referenced.
  • THUMB_SIZE — thumbnail size [width, height]. Thumbnails are scaled preserving aspect ratio and are not upscaled.
  • MAIN_THUMB_SIZE — main thumbnail size [width, height] used on the front page.
  • THUMB_QUALITY / MAIN_THUMB_QUALITY / FULL_QUALITY — webp encoding quality (1-100).
  • COLUMNS — number of columns in the gallery grid.
  • ROWS — number of rows per page (together with COLUMNS defines PER_PAGE if PER_PAGE is null).
  • PER_PAGE — images per gallery page. If null, computed as COLUMNS * ROWS.
  • TITLE — site title shown in the header.
  • TITLE_FONT_FAMILY / TITLE_FONT_SIZE_PX / TITLE_FONT_COLOR — title styling.
  • MENU_FONT_FAMILY / MENU_FONT_SIZE_PX / MENU_FONT_COLOR — menu/link styling.
  • SUBMENU_* — submenu styling.
  • MAIN_TEXT_FONT_FAMILY / MAIN_TEXT_FONT_SIZE_PX / MAIN_TEXT_FONT_COLOR — main text styling.
  • MAIN_COUNT — how many images appear in the main gallery (client chooses random MAIN_COUNT from assets/data/main_images.json; generator also writes a server-side sample).
  • FORCE_RECREATE — true/false: if true, output webp files are always regenerated; if false, files are skipped when target is newer than source.
  • CLEAN_NON_WEBP — true/false: if true, deletes .jpg/.jpeg/.png files from OUTPUT_DIR.
  • FULL_CROP — true/false: if true, full-size webp images in photos/ are center-cropped to the aspect ratio of MAIN_THUMB_SIZE; if false, images are only scaled.
  • FULL_LONG_SIDE_PX — if >0, sets the maximum long-side size for full images after cropping/scaling.
  • BAGUETTE_CSS_URL / BAGUETTE_JS_URL — URLs to download baguetteBox (lightbox). If download fails, stub files are created.

Required source folder structure (prepare before running) You must create and fill folders as in the example (or replicate the same items where pointed by config.json):

site_structure/
  images/                 # REQUIRED: images (.jpg/.jpeg/.png) and/or subfolders with images
    folder1/
      img1.jpg
      img2.png
    folder2/
      ...
  main/                   # REQUIRED: main content for the site
    text.txt              # REQUIRED: main page text (paragraphs separated by blank lines)
    banner.txt            # REQUIRED: cookie banner text
    logo.png (or jpg)     # REQUIRED: at least one image — will be used as site logo
  favicon/                # REQUIRED: favicon file (ico/png/jpg)

All listed elements must be present in the prepared structure: images, main/text.txt, main/banner.txt, at least one logo in main/, and a favicon in favicon/. These resources are necessary for successful site and banner generation.

Step-by-step usage (recommended order)

  1. Prepare and populate folders as described above.
  2. Edit config.json with correct absolute or relative paths and desired parameters.
  3. Run the site generator:
    • Python:
      python generate_gallery.py
      
    • Or Windows executable:
      generate_gallery.exe
      
    The script will:
    • discover source images in IMAGES_DIR,
    • create webp files: thumbnails (OUTPUT_DIR/thumbs), main thumbnails (OUTPUT_DIR/thumbs_main), full-size webp (OUTPUT_DIR/photos),
    • generate HTML (index and per-folder pages with pagination),
    • attempt to download baguetteBox assets (or create stubs),
    • write CSS/JS assets and assets/data/main_images.json.
  4. Run the cookie/banner script:
    • Python:
      python add_cookie_banner.py
      
    • Or Windows executable:
      add_cookie_banner.exe
      
    The script will:
    • write assets/js/cookie_consent.js and assets/css/cookie_consent.css into OUTPUT_DIR,
    • create privacy.html (assembled from index.html head/header/footer when possible),
    • patch all HTML files: remove or replace @import and <link> to Google Fonts (convert to <link data-href="...">), insert the cookie banner into <body>, add a privacy link to the footer, and ensure cookie_consent.js/css are included.
  5. Run a local HTTP server to test:
python -m http.server --directory output 8000

Open http://localhost:8000 in your browser.

Cookie banner behavior (what the script does)

  • assets/css/cookie_consent.css contains banner styles.
  • assets/js/cookie_consent.js:
    • shows the banner when consent is not stored,
    • on "Accept": stores 'accepted' in localStorage and dynamically loads all <link data-href="..."> (deferred Google Fonts),
    • on "Decline": stores 'declined' and hides the banner,
    • .cookie-manage-link elements reset stored consent and reopen the banner (used on the privacy page).
  • The script replaces <link href="https://fonts.googleapis.com/..."> with <link data-href="..."> and comments out/removes preconnect/@import entries for Google Fonts to prevent early requests.

Common issues and troubleshooting

  • Fonts still load immediately:
    • Check for manually inserted <link rel="stylesheet" href="https://fonts.googleapis.com/..."> or non-standard @import rules that add_cookie_banner.py did not detect. The script handles common patterns but complex custom code might require a manual edit: replace href with data-href.
  • Nothing was generated / no images found:
    • Ensure IMAGES_DIR contains files with .jpg, .jpeg, or .png extensions.
  • Permissions errors:
    • Verify write permissions for OUTPUT_DIR.
  • Lightbox (baguetteBox) doesn't work:
    • The script attempts to download baguetteBox from given URLs; if offline, stub files are created. You can manually place real baguetteBox.min.css and baguetteBox.min.js in assets/css and assets/js, or adjust the URLs and rerun the generator.

Generated output structure (example)

output/
  index.html
  privacy.html
  photos/              # full-size webp images
  thumbs/              # thumbnails webp
  thumbs_main/         # main thumbnails webp
  assets/
    css/
      styles.css
      baguetteBox.min.css
      cookie_consent.css
    js/
      gallery.js
      baguetteBox.min.js
      cookie_consent.js
    data/
      main_images.json
    logo/
  favicon/

License

  • MIT — free to use and modify. See the LICENSE file.

About

Generates a static site photo gallery from a folder of images. Генерирует статический сайт фото-галерею из папки с изображениями

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages