Thumbnail generation

Gallery3x2 min readPage 4 of 22
On this page 5

Thumbnails are generated once — on upload in the manager (and on regeneration). The site serves ready files and the server does not process images on every view. Processing is done by the Glide library.

Thumbnail sizes

Sizes are set in the media source: Media → Media Sources → “Gallery3x Source” → Properties, the gallery3x_thumbnails parameter — a JSON array with one object per size. After installation it contains:

[
  {"name": "small",  "w": 120,  "h": 90,  "q": 90,  "fit": "crop"},
  {"name": "medium", "w": 360,  "h": 270, "q": 100, "fit": "crop"},
  {"name": "big",    "w": 1200}
]
KeyDescription
nameRequired. Size name: the thumbnail folder and the [[+name_url]] placeholder ([[+small_url]], [[+big_url]]).
w, hWidth and height, px. You can set just one — the other follows the proportions.
fitHow to fit into w×h (see below).
qQuality 0–100 (for jpg, webp, avif). 90 by default.
fmFormat of this size. If the gallery3x.format setting is set, it wins.
othersAny Glide parameters: sharp, blur, bg, flip, or, etc.

fit values

fitResult
containDefault. Fit the whole image keeping proportions; the result may be smaller than w×h on one side.
maxLike contain, but never enlarges an image smaller than the given size.
fillFit the whole image and pad it to w×h with a background (colour — the bg parameter).
stretchStretch exactly to w×h ignoring proportions.
cropFill w×h and cut off the rest; the crop point — crop-top-left, crop-top, crop-center (default), crop-bottom-right, etc., or crop-25-75 (focal point in percent).

Global processing settings

In the system settings (namespace gallery3x) — for all sizes at once:

  • gallery3x.format — format of all thumbnails (webp by default; empty — same as the original). The original is not converted.
  • gallery3x.filters — effects separated by |: greyscale, sepia, blur=10, pixel=5, bri=10 (brightness −100…100), con=-5 (contrast), gam=1.5, sharp=15. Example: sepia|bri=10|con=-5.
  • gallery3x.watermark_path, gallery3x.watermark_position, gallery3x.watermark_padding — a watermark on all thumbnails (the original stays without it).
  • gallery3x.driver — imagick or gd.

Different sizes for different sections

Create another media source with its own gallery3x_thumbnails and bind it to templates with gallery3x.source_map, for example 12,14:5 — resources with templates 12 and 14 keep their images in source 5.

After changing the settings

Existing thumbnails do not change by themselves. Regenerate them: in the manager — right-click an image → “Regenerate thumbnails” (works for a selection too); for the whole site — the regenerate.php command-line script.

Glide’s intermediate files are kept in the .cache folder inside the source; it can be cleared.