This page covers the plumbing: where the photos live, how they get online, and what it costs. What your gallery looks like and how it’s organised (albums, series, projects, one long stream, or something else) is up to you.
You won’t write the code yourself. An AI coding assistant (such as Claude Code, Cursor, Gemini CLI, GitHub Copilot or OpenAI Codex) writes it for you, step by step, while you choose the photos, check the result and click a few buttons.
How it works
The photos
The website
- Your originals never leave your computer. Only smaller copies go online, with the location data (GPS) and camera serial numbers removed.
- GitHub keeps the site’s code and text, and a history of every change.
- Cloudflare Pages turns that code into a website, every time you send it a change.
- Cloudflare R2 stores the images. The website and the images are kept apart because a Cloudflare Pages site can hold only a limited number of files (20,000 on the free plan), and every photo becomes several files.
What you need
| Thing | What it’s for | Cost |
|---|---|---|
| A computer | Where your photos and the project live | – |
| An AI coding assistant | Writes the code for you | Free tiers exist; a paid plan (about 10–20 USD a month) goes further |
| A GitHub account | Keeps the code | Free |
| A Cloudflare account | Hosts the site and the images | Free for a personal gallery (see below) |
| A domain name (optional) | Your own address, like photos.your-name.com | About 10–15 USD a year |
What “free” means on Cloudflare
Three separate free allowances matter:
- Storage (R2): 10 GB. All the web copies of one photo together take about half a megabyte, so that is room for roughly 20,000 photos. Your originals don’t count; they never go there.
- Image requests (Pages Functions): 100,000 a day. Every image a browser loads goes through a small piece of code (a Function), and each one counts, including every thumbnail. An album page with 40 thumbnails uses 40. On the free plan, going over this doesn’t cost anything: images simply stop loading until the count resets the next day. Browsers keep images they’ve already loaded, so a returning visitor uses far fewer.
- Reading from storage (R2): 10 million a month, plus 1 million uploads a month. The daily limit above is reached long before these.
Sending images to visitors (bandwidth) is free and unlimited, and so are the site’s pages themselves.
R2 asks for a payment method before you can use it. Inside these allowances you aren’t charged, but nothing stops a charge if you go over the storage or R2 limits. A billing alert tells you after the fact; it isn’t a spending cap.
Step 1: Install the tools
Install these on your computer:
- Git, which sends your changes to GitHub.
- Node.js (the current long-term support version), which runs the publish script and builds the site.
- Your AI coding assistant.
Check: in a terminal, git --version and node --version each print a version number.
Step 2: Decide what your gallery is
Before anything is built, write down a few sentences about your gallery. There are no wrong answers, and you can change your mind later. Some questions to start with:
- How are the photos grouped? Albums by trip, series around an idea, numbered projects, one stream of single photos, photo essays with text between the pictures, or a mix.
- What makes it in? A gallery is a selection, not a copy of your whole library. A dozen strong photos from a trip usually say more than two hundred.
- What order? Newest first, oldest first, or an order you choose by hand.
- What goes with each photo? Nothing, a title, a caption, a date, a place, camera settings.
- How should it feel? Find two or three websites you like the look of, and note what you like about each.
Keep these notes in a text file in the project. They are what you’ll hand to the assistant in Step 4.
Step 3: Create the project folder
Make one folder for the whole project, with a few folders inside it:
| Folder | What goes in it |
|---|---|
library/ |
Your original photos, in folders that make sense to you (by year, by trip, by series…) |
content/ |
Small text files that describe your groupings and the words that go with the photos: titles, descriptions, captions. Its shape follows what you decided in Step 2 |
site/ |
The website’s code (the assistant writes this) |
scripts/ |
The publish script (the assistant writes this) |
Keep library/ out of GitHub. Your originals can hold your home location.
Keep the photos and content/ in ordinary files and folders that make sense without the website. Then the site is only a way of showing them: you could rebuild it, or move it away from GitHub or Cloudflare, without redoing your albums.
Step 4: Ask the assistant to build it, one piece at a time
Open the assistant in the project folder, give it your notes from Step 2, and ask for one piece at a time. Check each piece before the next. If installing something fails (the image tool sometimes does), paste the whole error into the assistant.
- The publish script. It reads the photos in
library/and the files incontent/, and makes web copies in two or three sizes (about 640, 1280 and 2048 pixels wide) in modern formats (AVIF and WebP), in a folder that stays on your computer. It removes GPS and serial numbers, checks that they are really gone, and writes a list of photos and groupings intosite/for the website to read. That list goes to GitHub with the code, so Cloudflare can build the site without your originals. - The website. A static site (plain pages built ahead of time; Astro is a good choice) that reads that list and shows your photos the way you described in Step 2. Look at it on your computer before it goes online, and ask for changes until it feels right.
- The upload. Code in the publish script that sends new web copies to Cloudflare R2. It runs once you’ve set up R2 in Step 6.
The assistant can’t see your photos the way you do, and it can make mistakes you won’t spot in the code. So check the results instead:
- Start with a handful of photos, not your whole library.
- Open a few web copies and compare them with the originals: the right way up, the colours the same, never larger than the original.
- Check that the location is gone. Ask the assistant how to read a web copy’s metadata, or drop one into an online EXIF viewer, and look for GPS.
Check: the site works on your computer, with your own photos.
Step 5: Put the code on GitHub
- On GitHub, create a new private repository.
- Ask the assistant to connect the project folder to it and push. Make sure your originals (
library/), the web copies and any file holding keys (usually.env) are left out.
Check: the repository on GitHub shows your code, and no photos and no keys.
A private repository is still on someone else’s computer. Everything in content/ and the photo list goes there: album names, captions, dates, and the names of your photo folders. If a caption or a folder name gives away where you live, change it before you push.
Step 6: Set up the image storage (Cloudflare R2)
- In the Cloudflare dashboard, open R2 Object Storage and turn it on. Add a payment method if Cloudflare asks for one; you won’t be charged inside the free allowance.
- Create a bucket, for example
my-gallery-photos. Leave public access off. - On the R2 page, under Account Details, select Manage next to API Tokens. Create a token with Object Read & Write permission, limited to that bucket.
- Ask the assistant to create an empty
.envfile with the slots its upload code needs. Then fill in the Account ID, Access Key ID, Secret Access Key and bucket name yourself, with a text editor. Don’t paste keys into a chat, an email or GitHub. - Run the publish script. It uploads the web copies.
Leaving public access off means nobody can list or browse the bucket. Visitors’ browsers never talk to R2 directly: they ask the website for an image, and a small Function on the site fetches it from the bucket and passes it on. The keys in .env are only for uploading from your computer; they never go online.
Step 7: Put the site online (Cloudflare Pages)
- In Cloudflare, go to Workers & Pages → Create → Pages → Connect to Git, and pick your repository.
- Build settings:
- Root directory:
site - Build command:
npm run build - Build output directory:
dist
- Root directory:
- Save and Deploy. After a minute or two you get an address like
my-gallery.pages.dev. - In the Pages project’s Settings → Bindings, add an R2 bucket binding, so the site can show the images. Use the variable name the assistant’s code expects (ask it, for example
PHOTOS) and pick your bucket. Then retry the latest deployment.
If the build fails, open the failed deployment, copy its log and give it to the assistant. If the log mentions the Node.js version, add a variable NODE_VERSION set to the first number that node --version shows on your computer (for example 24) under Settings → Variables and Secrets, then retry.
Check: the pages.dev address opens your gallery, with photos.
Step 8: Use your own address (optional)
- In the Pages project, open Custom domains and add your address, such as
photos.your-name.com. Always start here, before touching any DNS settings; a record added on its own leaves the address broken. - If your domain’s DNS is already managed by Cloudflare, it adds the record for you. Otherwise Cloudflare shows one record to add (a CNAME): add exactly that record where you bought your domain. Don’t change any other records: they may run your email or another site.
- Wait a few minutes. The padlock (HTTPS) is set up for you.
Adding photos later
- Put the new photos in
library/. - Add or update their text in
content/: a new album, the next part of a series, a caption, whatever your gallery uses. - Run the publish script.
- Push to GitHub. Cloudflare updates the site within a minute or two.
Removing or replacing photos
Take the photo out of content/ (or replace the file in library/), run the publish script and push. The site stops showing it straight away, but its old web copies stay in R2 until you clear them out. Ask the assistant for a cleanup option that first lists what it would delete, and only deletes when you run it again with a separate switch. Never let it delete something from R2 just because it’s missing on your computer: a moved folder or an unplugged drive looks the same.
Good habits
- Back up your originals properly. R2 only has small copies, so it’s no backup. Keep three copies of your library, on at least two different drives, with one of them somewhere else (cloud backup, or a drive at a friend’s or at work).
- Turn on a billing alert in Cloudflare, so you’d hear about any charge.
- Add an RSS feed, so people can follow new work in a feed reader.
For AI assistants: the brief
If you ask an AI assistant to build this, you can give it this summary:
Build a personal photo gallery. How it is organised and how it looks are described in my notes: [paste your notes from Step 2]. Ask me about anything they leave open before you build it.
- Originals stay local in
library/(git-ignored).- Content: plain-text files (Markdown with front matter, or YAML) in
content/describe how the photos are grouped and the words that go with them. Design their format from my notes, and keep it simple enough for me to edit by hand.- Publish script (Node.js, TypeScript, sharp): read the originals and the content files, give each photo a stable ID, make 640/1280/2048 px AVIF and WebP copies with hashed file names in a git-ignored folder, strip GPS and serial numbers and verify they’re gone, write JSON data into
site/(committed to Git, so Cloudflare can build without the originals), and upload new copies to a Cloudflare R2 bucket using keys from a git-ignored.env, with a long immutable Cache-Control.- Image quality: apply the EXIF orientation before stripping metadata, keep the aspect ratio, never upscale, and convert to sRGB (embed the profile). Only redo copies whose original changed.
- Updates and deletions: support a dry run that changes nothing. Never delete from R2 automatically: list unreferenced objects, delete them only with an explicit flag, and only names the script itself made.
- Website: a static Astro site in
site/that reads the JSON. Deploy it with Cloudflare Pages from a private GitHub repository (rootsite, buildnpm run build, outputdist). Serve images from the R2 bucket through a Pages Function bound to the bucket (public access off), and tell me the binding name to set in Cloudflare. The Function serves only file names that match the script’s naming pattern (anything else is 404, as is a missing object), with the stored content type and cache headers. Locally, serve the same images from the publish script’s output folder.- Performance and accessibility: a
<picture>with an AVIF source first and WebP as the fallback, each withsrcsetandsizesso phones get small copies, lazy-load images below the fold, set width and height to avoid layout jumps. Alt text from my captions, keyboard navigation with visible focus, and respect reduced motion.- Workflow: add photos, edit content, run publish,
git push, and Cloudflare deploys.- Build it in stages and stop for review after each one: the content format, the publish script, the local site, the upload, deployment. Test with a few photos first, and never commit originals, web copies or
.env.