Skip to content

Files Thumbnails And Gallery Design

Ed Mozley edited this page Nov 23, 2026 · 3 revisions

Thumbnails, a gallery viewer and pictures in Knowledge - design

Status: design agreed by Ed, 22 November 2026 (decisions). Thumbnails BUILT on 23 November 2026 for 5.10.0 (pictures, PDFs, Make thumbnail, the Thumbnails tab, the Thumbnails view). The gallery viewer BUILT on 23 November 2026 for 5.11.0 (previous / next, arrow keys, opening a selection together, Open separately, the slideshow) - see Files: Several files at once. Knowledge and the filmstrip are next. Built differently from the design in two places - see What changed while building. Issue: #424 from @proseriox - open several files and step between them, thumbnails and a thumbnail view, and using Files from Knowledge.

In one paragraph: every picture and PDF in Files gets a thumbnail - a small WebP picture, about 256 pixels on its longest side and typically 5-15 KB - made once, stored, and shared by every copy of the same file. Pictures are shrunk by the server; a PDF's first page is drawn by the browser of the person uploading it, who already has the file. Opening a folder of 100 photos or 100 PDFs then loads 100 small pictures that already exist. A Thumbnails tab in Files settings shows any backlog and clears it with a progress display, and Make thumbnail on a file's right-click menu fixes stragglers. The viewer gains previous / next and a slideshow, Documents gains a Thumbnails view, and the Knowledge editor can insert a picture from Files.

Contents

  1. What exists today
  2. Thumbnails
  3. The backlog and the Thumbnails tab
  4. Privacy and permissions
  5. The gallery viewer
  6. Pictures from Files in Knowledge
  7. Build order
  8. Decisions
  9. How it will be tested

1. What exists today

#424 asks for Today
Open several files, step between them, a gallery The viewer (assets/js/files-viewer.js) opens one file per window; there is no previous / next
Thumbnails and view modes Documents has Icons and Details views; icons show the file's type, not its contents
Files in Knowledge An article's Documents panel already attaches a file From Files, as a link or a copy (Files β†’ Settings β†’ Sharing). Nothing puts a Files picture inside the article text

Two facts that shape the design:

  • The Docker image has no image library. docker/php-extensions.txt installs pdo_mysql, ldap, zip and intl; PHP's image extension, GD, is not among them. Shrinking a picture on the server needs it.
  • No PHP install can draw a PDF on its own. That needs Imagick with Ghostscript, which most installs do not have. The browser can: the viewer already ships Mozilla's pdf.js.

2. Thumbnails

What a thumbnail is

Size Longest side 256 px (sharp at 2x in a large icon), aspect kept, never enlarged
Format WebP, quality about 75 - typically 5-15 KB. JPEG where GD has no WebP
Made from Pictures: JPEG, PNG, GIF (first frame), WebP. PDFs: page 1
Never made from SVG (never rasterised on the server - a script-carrying format), HEIC (GD cannot read it), video, everything else - they keep their type icon
Keyed by The version's SHA-256 - so every copy of the same file shares one thumbnail, a new version gets a new one, and restoring an old version finds its old one again

Stored once

A new table, one row per fingerprint:

CREATE TABLE files_thumbnails (
    sha256        CHAR(64) NOT NULL PRIMARY KEY,
    status        VARCHAR(16) NOT NULL,   -- ready | waiting | too_large | unsupported | failed
    storage_key   VARCHAR(255) NULL,      -- in the active store, e.g. thumbs/ab/abcdef....webp
    mime_type     VARCHAR(50) NULL,
    width         SMALLINT NULL,
    height        SMALLINT NULL,
    bytes         INT NULL,
    made_by       VARCHAR(16) NULL,       -- server | browser
    made_by_id    INT NULL,               -- the analyst whose browser drew it
    detail        VARCHAR(255) NULL,      -- why it could not be made
    created_datetime DATETIME NOT NULL
);

The picture itself goes in the same store as the files - local folder or S3 - through the existing StorageDriver (putFile, readTo), under thumbs/. Nothing new to configure, and an S3 install keeps everything in its bucket.

A status other than ready is remembered too, so a picture too big to shrink or a damaged file is tried once and set aside, not retried on every folder open - and the backlog can reach zero.

Who makes it

File When it arrives by upload Otherwise (existing files, Save to Files from a ticket, copies, the API)
Picture The server shrinks it when the upload completes The server shrinks it the first time it is asked for
PDF The uploader's browser draws page 1 from the file on their own computer - nothing downloaded - and sends the small picture with the last piece of the upload waiting: drawn by the browser of someone with Upload on the folder when they open it (two at a time, icons on screen only), or by Make thumbnail, or by the Thumbnails tab

The server shrinking a picture reads it through the store, checks its pixel count before decoding (a 20,000 x 20,000 PNG would need over 1.5 GB as a bitmap), and gives up as too_large above a ceiling of about 40 megapixels. Very large files are read to a temporary copy rather than into memory.

A thumbnail sent by a browser is never trusted as sent: it must be a real image (checked by its bytes, not its name), at most 512 px and 100 KB, and the server re-encodes it with GD, so nothing hidden in the file survives. Without GD the PDF thumbnail is refused and the PDF keeps its icon - pictures and PDFs both need GD on the server.

Shown

  • Documents asks for a thumbnail only for icons on screen, and only for files whose row says ready - the folder listing carries that, so a folder of 100 files with no thumbnails makes no extra requests at all.
  • api/files/thumbnail.php?item=ID checks View on the folder, exactly as opening the file does, and serves the stored picture with a long cache lifetime keyed by the fingerprint - a browser fetches each one once.
  • Thumbnails show in Icons, the new larger Thumbnails view, Recent, Search and the viewer's filmstrip.

Removed

A thumbnail is deleted when no version anywhere still has its fingerprint - by the same code that permanently deletes versions (the recycle bin's purge, Delete permanently, version delete).

The Docker image

GD is added to docker/php-extensions.txt (with the reason), so the build's own check refuses to publish an image without it, and tests/docker-php-extensions.php knows the code now calls it. An install without GD shows type icons everywhere and says so on the Thumbnails tab; nothing fails.

3. The backlog and the Thumbnails tab

Files β†’ Settings β†’ Thumbnails (Files administrators), beside Storage, Versions, Sharing and Recycle bin:

  • Thumbnails switch - on by default.
  • The backlog, counted by fingerprint: pictures to make, PDFs to make (of which: in folders you can open / waiting for someone with access), and set aside - too large, unsupported, failed - with a Try again for failures.
  • Clear works through the backlog in batches: pictures by the server, PDFs in folders the administrator can open by their browser (two at a time). It can be paused and continued, survives a page reload, and stops cleanly if the tab is closed.
  • The progress display is meant to be enjoyable to watch: a running count, a bar that fills, and plain tiles that pop into a grid as each thumbnail is made - green for made, grey for set aside. The tiles never show the pictures or their names (see privacy).
  • Is GD here? - a line saying whether this server can make thumbnails at all.

No background job is needed. One could later sweep old files on installs that do have Ghostscript, but nothing depends on it.

4. Privacy and permissions

Files promises that nothing is visible to anybody until it is shared with them - administrators included. Thumbnails keep that promise:

Rule
Seeing a thumbnail View on the folder - the same as opening the file
A folder with a watermark No thumbnails: a clean picture of the page would get round the watermark
The Thumbnails tab clearing pictures Fine everywhere - the server shrinks them; the administrator sees counts and plain tiles only
The Thumbnails tab clearing PDFs Only in folders the administrator can open. Drawing page 1 means opening the PDF in a browser, so a PDF in a folder not shared with them is counted as waiting for someone with access and done when somebody who can open it does
Make thumbnail (right-click a file) Pictures: anyone with View (the server does it). PDFs: Upload on the folder - the same rule as the automatic fill-in, so somebody with View only cannot plant a misleading picture. Also redraws a thumbnail that looks wrong
Sending a PDF thumbnail from a browser Upload on the folder; re-encoded by the server
The audit trail Showing thumbnails is not recorded as opening a file (it would bury the real opens). Making one is recorded once, as thumbnail made

5. The gallery viewer

  • Previous / next in the viewer's title bar, and the left / right arrow keys, step through the files you had selected when you opened it - or, with one file opened, through the folder in its current order and filter.
  • A filmstrip of thumbnails along the bottom (hidden for a single file), click to jump.
  • Slideshow (pictures): full window, a few seconds each, Space to pause, Esc to stop.
  • Every file stepped to is checked and recorded as if opened - the audit trail keeps one entry per file viewed, and View only, the watermark and the version shown work exactly as now.
  • Selecting several files and pressing Enter (or Open on the menu) opens them in one viewer, instead of one window each.

6. Pictures from Files in Knowledge

The article editor gains Insert picture from Files: the Files picker opens, limited to pictures, and the chosen picture goes into the article as a copy - the same as a picture inserted from the computer today (scaled, embedded, capped at 3 MB).

Why a copy, not a link: an article is read by people who mostly cannot open the Files folder - other analysts, and portal users who can never open Files at all. A linked picture would be blank for every one of them. Documents keep both choices, as now: a PDF attached From Files as a link stays the single source, and readers without access see that a file is attached.

7. Build order

Each step is useful on its own and shippable alone:

  1. The gallery viewer - previous / next, arrow keys, opening a selection together, slideshow. Needs nothing new on the server.
  2. Picture thumbnails - the table, GD in Docker, server shrinking on upload and on first request, Icons view using them, the new Thumbnails view.
  3. PDF thumbnails - drawn at upload by the uploader's browser; filled in for folder managers; Make thumbnail.
  4. The Thumbnails tab - backlog, Clear, progress display.
  5. Insert picture from Files in Knowledge.
  6. The filmstrip in the viewer, once thumbnails exist.

What changed while building

Design said Built Why
The picture in the store, under thumbs/ In the database, files_thumbnails.data (MEDIUMBLOB, a few KB) Moving Files to another storage location copies only files_versions keys - thumbnails in the store would have been left behind on every move. And serving a 5 KB picture from S3 through PHP costs a round trip each; from the database it is one row.
Who may clear PDFs: folders the administrator can open Folders they can upload to The same rule as everywhere else a browser sends a thumbnail, so there is one rule, not two.
A PDF drawn from the viewer's view.php Its own byte source, thumbnail.php?source=1 view.php records every read as the file being opened; drawing 100 thumbnails would have buried the real opens. The new source answers only someone with Upload, only while the PDF has no thumbnail, and is recorded once as thumbnail.
(not in the design) A permission of its own, files.thumbnails, for the tab Every Files settings tab has one; not sensitive, because it never shows a file the person could not open.
Enter on a selection always opens one viewer A personal setting, Opening several files in Personalise: one viewer (default) or a window each, up to 10 - plus Open separately on the right-click menu Ed asked whether Enter should offer a choice. A question on every Enter gets old fast; separate windows still have a real use (two side by side, with snap assist) - so a setting, today's design as the default, and a menu item for the one-off
The slideshow runs "a few seconds each" Plays once, from the current picture to the last Every picture shown is an audited open; a looping slideshow left running would add an entry every four seconds
(not in the design) exif in the Docker image too Phone photos are stored sideways with an EXIF note saying so; without it their thumbnails would be sideways.

8. Decisions

Date Decision
22 Nov 2026 Thumbnails are made once and stored, not made on every view - "a folder with 100 PDFs could be a nightmare" (Ed). Pictures are downscaled to a few KB the same way
22 Nov 2026 A PDF's page 1 is drawn by the browser and saved as a picture; at upload by the uploader's browser, from the local file
22 Nov 2026 A Thumbnails settings tab shows the backlog and clears it with a fun progress display
22 Nov 2026 Keep the privacy promise: clearing the backlog never opens a PDF in a folder the administrator has not been given; those wait for someone with access
22 Nov 2026 Make thumbnail on a file's right-click menu, to fix stragglers
22 Nov 2026 No background job needed
23 Nov 2026 Several files selected + Enter: one viewer by default; a personal setting to open a window each instead (Ed: "can we make it a setting?"). Above 10 files, always one viewer. Open separately on the right-click menu for 2 to 10
23 Nov 2026 5 pictures and 1 PDF open as one viewer of 6 items; the PDF shows as a PDF when stepped to; the slideshow plays only the pictures

9. How it will be tested

  • Thumbnails: a picture of each format becomes a WebP under 256 px; two copies share one row; a new version gets a new thumbnail and the old one survives while its version exists; a 50-megapixel PNG is set aside as too_large without exhausting memory; SVG and HEIC keep their icons; S3 store and local store both.
  • Permissions: no View - 404; watermark folder - no thumbnail; a PDF thumbnail sent with View only - refused; a crafted "thumbnail" with trailing data - re-encoded, nothing survives; showing thumbnails adds no audit entries.
  • Backlog: counts match a hand count; Clear empties pictures everywhere and PDFs only where the administrator has access; the rest are reported as waiting; pause and continue.
  • Viewer: stepping through a selection and a folder in its sort order; each step recorded as an open; View only and watermark kept on every step.
  • Without GD: every screen still works, with icons, and the tab says why.

Related

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally