Skip to main content
Documentation menu

Commands

spg build

Build the static HTML gallery, thumbnails and social media image.

Creates the static HTML gallery website.

spg build [options]

How it works

The command will generate the static HTML gallery from the gallery.json file and the linked photos and videos. It will also generate thumbnails for the photos and videos, as well as a social media image for the gallery.

If you have created the gallery in a different folder from the photos folder, the command will copy the photos and videos to the gallery folder. If you have set the -b or --base-url option, the command will link to the photos and videos from the external URL instead of copying them. Additionally, you can also set the -t or --thumbs-base-url option to specify the base URL for the thumbnails.

Options

Option Description Default
-g, --gallery <path> Path to gallery directory Current directory
-r, --recursive Build all galleries false
-b, --base-url <url> Base URL for external hosting None
-t, --thumbs-base-url <url> Base URL for external hosting of thumbnails None
--assets-base-url <url> Shared URL for the built CSS and JS files gallery.json or gallery/assets/
--theme <package|path> Theme package name or local path gallery.json theme or theme-modern
--thumbnail-size <pixels> Override thumbnail size in pixels From config hierarchy
--thumbnail-edge <mode> Override size mode: auto, width, or height From config hierarchy
--no-scan Do not scan for new photos true
--prune Remove missing source files from gallery.json false
--section <title|number> Add newly scanned files to this section Last section
--web-videos Create web-friendly MP4 playback copies false
--no-thumbnails Skip creating thumbnails true
-y, --yes Confirm build prompts for non-interactive runs false
-v, --verbose Show detailed output
-q, --quiet Only show warnings/errors
-h, --help Show command help

Examples

# Build gallery in current directory
spg build

# Build specific gallery
spg build -g /path/to/gallery

# Build all galleries recursively
spg build -r

# Build with external base URL (no photo copying) - useful for hosting photos separately from the gallery
spg build -b https://photos.example.com/

# Build with external base URL for photos and thumbnails
spg build -b https://photos.example.com/ -t https://photos.example.com/thumbnails

# Load the theme CSS and JS from a shared location (saved to gallery.json)
spg build -r --assets-base-url https://cdn.example.com/simple-photo-gallery

# Build without scanning for new photos
spg build --no-scan

# Remove deleted source files while scanning
spg build --prune

# Add newly scanned photos to the section titled "Kyoto" instead of the last section
spg build --section "Kyoto"

# Add newly scanned photos to the second section
spg build --section 2

# Build non-interactively when photos must be copied into the gallery output
spg build --yes

# Build without creating thumbnails
spg build --no-thumbnails

# Build with a custom theme package (npm)
spg build --theme @your-org/your-private-theme

# Build with a local theme (path)
spg build --theme ./themes/my-local-theme

# Build with custom thumbnail settings (overrides gallery.json and theme)
spg build --thumbnail-size 400 --thumbnail-edge height

Adding new photos to a section

By default, the build scans the photos folder and appends any new photos and videos to the last section of gallery.json. Use --section to add them to a different section instead:

  • Pass the section title, for example --section "Kyoto". An exact match is preferred; otherwise the title is matched case-insensitively.
  • Or pass the section number, starting at 1, for example --section 2. Untitled sections can only be selected by number.

The section must already exist in gallery.json. If no section matches, if several sections have the same title, or if a numeric value matches the title of one section and the number of another, the build stops with an error that lists the available sections, and gallery.json is left unchanged. The section is only looked up when new files are found, so a build without new files succeeds even if the section does not exist (for example, in other galleries of a recursive build). --section cannot be combined with --no-scan.

Web-friendly videos

Run spg build --web-videos to enable conversion for that build. It requires FFmpeg with the libx264 and AAC encoders and ffprobe. A regular spg build uses the original video or any sources you configured in gallery.json.

The CLI uses a local MP4 directly when it contains H.264 video in 8-bit 4:2:0, has AAC audio or no audio, fits within 1920 × 1080 (1080 × 1920 for portrait), and is at most 8 Mbit/s. Other local videos get one H.264 MP4 with AAC when audio is present. The copy preserves orientation, fits within the same bounds, and places playback metadata at the start of the file for streaming. Large clips can take several minutes.

Publish the generated gallery/videos/ directory alongside the HTML. Repeated flagged builds reuse completed copies for unchanged inputs. The build supplies the generated URLs to the theme and leaves your originals and configured source lists intact. Videos with explicit videoSources take precedence, and remote-only originals are skipped. Run spg clean to clear generated files, including cached encodes.

Custom Themes

You can use custom themes by specifying the --theme option. Themes can be:

  • npm packages: Install as a dependency and use the package name (e.g., @your-org/your-private-theme)
  • Local paths: Use a relative or absolute path to a local theme directory (e.g., ./themes/my-local-theme)

See the Custom Themes guide for requirements and how to create your own theme.