appscript.dev
Automation Intermediate Drive Sheets

Generate thumbnails and a visual asset catalog

Build a browsable gallery Sheet of Northwind's Drive assets with thumbnail previews.

Published Aug 9, 2025

Northwind keeps hundreds of images in Drive — shoot exports, logo variants, stock crops — and Drive’s grid view is fine until someone asks “do we have a landscape version of that header?”. Then it is a lot of clicking, because Drive only shows you a name and a small icon, not a real preview you can scan.

This script turns a Drive folder into a browsable catalog in a Sheet. Each image becomes a row with a live thumbnail rendered straight in the cell, plus its name, a link, and its size. The result is a gallery anyone can open, scroll, and search — no Drive permissions juggling, no downloading files to look at them.

What you’ll need

  • A Drive folder of images — the folder ID goes in the config below.
  • A blank Google Sheet to hold the catalog — its ID goes in the config too.
  • Nothing else. The thumbnails use Drive’s own preview URL through the IMAGE() formula, so there is no image hosting to set up.

The script

// The Drive folder whose images you want catalogued.
const ASSET_FOLDER_ID = '1abcAssetFolderId';

// The blank Sheet that will hold the catalog.
const CATALOG_SHEET_ID = '1abcCatalogId';

// Thumbnail width in pixels. Drive scales the preview to this width.
const THUMB_WIDTH = 200;

// Row height in pixels — tall enough to show the thumbnail comfortably.
const ROW_HEIGHT = 80;

/**
 * Scans the asset folder for images and rebuilds a catalog Sheet with
 * an in-cell thumbnail, name, link, and size for each one.
 */
function buildAssetCatalog() {
  // 1. Walk every file in the folder, keeping only images.
  const files = DriveApp.getFolderById(ASSET_FOLDER_ID).getFiles();
  const rows = [];
  while (files.hasNext()) {
    const f = files.next();
    if (!f.getMimeType().startsWith('image/')) continue;

    // 2. Build one row: name, a live thumbnail formula, a link, the size.
    //    IMAGE() pulls Drive's own preview, so nothing is re-hosted.
    rows.push([
      f.getName(),
      `=IMAGE("https://drive.google.com/thumbnail?id=${f.getId()}&sz=w${THUMB_WIDTH}")`,
      f.getUrl(),
      f.getSize(),
    ]);
  }

  // 3. Bail out before touching the Sheet if the folder held no images.
  if (!rows.length) {
    Logger.log('No images found in the asset folder — nothing to catalogue.');
    return;
  }

  // 4. Rebuild the catalog from scratch so it always reflects the folder.
  const sheet = SpreadsheetApp.openById(CATALOG_SHEET_ID).getSheets()[0];
  sheet.clear();
  sheet.getRange(1, 1, 1, 4).setValues([['Name', 'Thumb', 'Link', 'Size']]);

  // 5. Write all rows in one call, then give them room for the thumbnails.
  sheet.getRange(2, 1, rows.length, 4).setValues(rows);
  sheet.setRowHeights(2, rows.length, ROW_HEIGHT);
  Logger.log('Catalogued ' + rows.length + ' images.');
}

How it works

  1. buildAssetCatalog opens the asset folder and iterates every file, skipping anything whose MIME type does not start with image/ — so PDFs and stray documents never end up in the gallery.
  2. For each image it builds a four-cell row. The second cell is an IMAGE() formula pointing at Drive’s thumbnail endpoint, which renders a live preview inside the cell when the Sheet recalculates.
  3. If the folder turned up no images, it logs a message and stops before clearing the Sheet — so a misconfigured folder ID never wipes the catalog.
  4. It clears the first sheet and writes a fresh header row, rebuilding the catalog completely on every run.
  5. It writes every row in a single setValues call, then sets the row heights so each thumbnail has space to display instead of being clipped.

Example run

Say the asset folder holds three images. After a run, the catalog Sheet looks like this — the Thumb column shows an actual preview, not the formula text:

NameThumbLinkSize
header-landscape.jpg(rendered preview)https://drive.google.com/file/d/482143
logo-mark-white.png(rendered preview)https://drive.google.com/file/d/18204
product-shot-03.jpg(rendered preview)https://drive.google.com/file/d/1294870

Now anyone can scroll the Sheet, eyeball the previews, and click straight through to the file in Drive — no downloading required.

Run it

This is an on-demand job — run it whenever the folder’s contents have changed:

  1. In the Apps Script editor, select buildAssetCatalog and click Run.
  2. Approve the authorisation prompt the first time.
  3. Open the catalog Sheet — give it a moment for the IMAGE() formulas to render their previews.

If the folder changes often, add a daily time-driven trigger so the catalog stays current without anyone remembering to refresh it.

Watch out for

  • IMAGE() only renders previews for files anyone with the link can view. If a thumbnail cell shows an error, open that file’s sharing settings in Drive.
  • The catalog covers one folder, not its subfolders. If your assets are nested, the script needs a recursive walk like the one in Flag oversized media eating your quota.
  • Size is reported in raw bytes. Divide by 1024 * 1024 in a spare column if you would rather read megabytes.
  • Drive’s thumbnail endpoint is rate-limited. A folder of several thousand images may render previews slowly the first time the Sheet opens — they cache after that.
  • The script rebuilds the Sheet every run, so any manual notes you add to the catalog will be wiped. Keep notes on a second tab the script never touches.

Related