Skip to main content

Thumbnail

Generate a smaller preview image from an image, video, or document.

File-first​

width and height are both optional. Give one and the other is derived from the source's aspect ratio; give neither and the longest edge becomes 320px — either way the image is never distorted. The fit option (max / crop / scale) controls how the source is fitted to the requested dimensions. A null dimension is rejected with a GislConfigError before any upload — omit the key instead.

const result = await client
.file('./photo.jpg')
.thumbnail({ width: 200, height: 200 })
.run({ maxWait: '5m' });

console.log(result.url);

Options by media type​

OptionValuesDefaultApplies to
width / height1–16384Both omitted: longest edge 320px. One omitted: derived from the source aspect ratio.All. Width × height ≤ 16 MP. Video rounds each down to an even number.
fitmax · crop · scalecropAll.
formatjpg · png · webpjpgAll. Note jpg, not jpeg.
quality1–10085 (jpg, webp); 70 (png)Image input: jpg, webp and png. Video and documents: jpg and webp only.
background#RRGGBB—Image input with format: 'jpg'.
timestampa string: seconds ('5') or HH:MM:SS'00:00:01'Video — the frame to extract.
sourcepage · coverpagePDF, Office and OpenDocument. cover has no effect for these.
page≥ 11PDF, Office and OpenDocument, with source: 'page'.
  • Image input: JPEG, PNG, GIF, WebP, TIFF, BMP, AVIF and HEIC.
  • Video input: MP4, WebM and MOV. Input over 5 minutes (the long-form tier) is planned for thumbnail.
  • EPUB takes source: 'cover' only — its default — and extracts the embedded cover image; source: 'page' is rejected.
// A frame five seconds in.
const frame = await client
.file('./clip.mp4')
.thumbnail({ width: 640, height: 360, timestamp: '5', format: 'webp' })
.run({ maxWait: '5m' });

// Page 2 of a PDF.
const page = await client
.file('./report.pdf')
.thumbnail({ width: 400, height: 520, page: 2, format: 'png' })
.run({ maxWait: '5m' });

Chaining​

Thumbnail the output of a prior step in the same workflow — for example, compress first, then thumbnail the compressed result:

import { OptimizeFor } from '@giveitsmaller/sdk';

const result = await client
.file('./photo.jpg')
.compress(OptimizeFor.Size)
.thumbnail({ width: 200, height: 200 })
.run({ maxWait: '5m' });

See also​