# Extract thumbnail images from documents

Robot: `/document/thumbs`

🤖/document/thumbs generates an image for each page in a PDF file or an animated GIF file that loops through all pages.

## Things to keep in mind

* If you convert a multi-page PDF file into several images, all result images will be sorted with the first image being the thumbnail of the first document page, etc.
* You can also check the `meta.thumb_index` key of each result image to find out which page it corresponds to. Keep in mind that these thumb indices **start at 0,** not at 1.

Stage: ga

## Usage example

Convert all pages of a PDF document into separate 200px-wide images:

```json
{
  "steps": {
    "thumbnailed": {
      "use": ":original",
      "robot": "/document/thumbs",
      "width": 200,
      "resize_strategy": "fit",
      "trim_whitespace": false
    }
  }
}
```

## Parameters

* `interpolate`: Controls whether Assembly Variables are interpolated for individual instruction fields.

  By default, most Robot instruction fields interpolate Assembly Variables. Set this to `false` to treat every instruction field as literal text, or set an individual field path to `false` to treat only that field as literal text. For Robot-specific fields that are literal by default, set this to `true` or set that field path to `true` to opt back into interpolation.

  Use field names such as `path`, or dotted paths such as `ffmpeg.vf` for nested objects.

* `output_meta`: Allows you to specify a set of metadata that is more expensive on CPU power to calculate, and thus is disabled by default to keep your Assemblies processing fast.

  For images, you can add `"has_transparency": true` in this object to extract if the image contains transparent parts and `"dominant_colors": true` to extract an array of hexadecimal color codes from the image.

  For images, you can also add `"blurhash": true` to extract a [BlurHash](https://blurha.sh) string — a compact representation of a placeholder for the image, useful for showing a blurred preview while the full image loads.

  For videos, you can add the `"colorspace": true` parameter to extract the colorspace of the output video.

  For videos, you can also add `"interlaced": true` to detect whether the video is interlaced. This combines the cheap ffprobe `field_order` flag with a bounded `idet` sampling pass over the first frames of the source, exposing `interlaced`, `field_order`, and a diagnostic `interlace_detection` object under `file.meta`. This is computationally expensive and billed accordingly.

  For audio, you can add `"mean_volume": true` to get a single value representing the mean average volume of the audio file.

  You can also set this to `false` to skip metadata extraction and speed up transcoding.

* `user_meta`: Adds custom metadata to each file emitted by this Robot without modifying the file’s contents.

  The values are merged with any existing `user_meta` carried by the input file. If both objects contain the same key, this Robot’s value takes precedence. Assembly Variables are supported, for example `{ "internal_file_id": "${file.id}" }`.

* `result`: Whether the results of this Step should be present in the Assembly Status JSON

* `queue`: Setting the queue to 'batch', manually downgrades the priority of jobs for this step to avoid consuming Priority job slots for jobs that don't need zero queue waiting times

* `force_accept`: Force a Robot to accept a file type it would have ignored.

  By default, Robots ignore files they are not familiar with.
  [🤖/video/encode](/docs/robots/video-encode.md), for
  example, will happily ignore input images.

  With the `force_accept` parameter set to `true`, you can force Robots to accept all files thrown at them.
  This will typically lead to errors and should only be used for debugging or combatting edge cases.

* `ignore_errors`: Ignore errors during specific phases of processing.

  Setting this to `["meta"]` will cause the Robot to ignore errors during metadata extraction.

  Setting this to `["execute"]` will cause the Robot to ignore errors during the main execution phase.

  Setting this to `true` is equivalent to `["meta", "execute"]` and will ignore errors in both phases.

* `use`: Specifies which Step(s) to use as input.

  * You can pick any names for Steps except `":original"` (reserved for user uploads handled by Transloadit)
  * You can provide several Steps as input with arrays:
    ```json
    {
      "use": [
        ":original",
        "encoded",
        "resized"
      ]
    }
    ```
  * You can also tag input Steps with `as` to pass semantic intent to robots:
    ```json
    {
      "use": [
        {
          "name": ":original",
          "as": "image"
        },
        {
          "name": ":original",
          "as": "mask"
        }
      ]
    }
    ```

  > [!Tip]
  > That's likely all you need to know about `use`, but you can view [Advanced use cases](/docs/topics/use-parameter.md).

* `imagemagick_stack`

* `page`: The PDF page that you want to convert to an image. By default the value is `null` which means that all pages will be converted into images.

* `page_range`: A page range to extract, in the format `"start-end"` (e.g., `"1-20"`). Extraction starts from the first page in the range and proceeds sequentially, stopping gracefully when a page does not exist. This is useful for PDFs where the total page count cannot be determined.

  This parameter cannot be used together with `page`, and is not supported with GIF format. When `page_range` is set, the robot does not need to know the total page count upfront, making it robust for PDFs that fail page count detection.

* `format`: The format of the extracted image(s).

  If you specify the value `"gif"`, then an animated gif cycling through all pages is created. Please check out [this demo](/demos/document-processing/convert-all-pages-of-a-document-into-an-animated-gif.md) to learn more about this.

* `delay`: If your output format is `"gif"` then this parameter sets the number of 100th seconds to pass before the next frame is shown in the animation. Set this to `100` for example to allow 1 second to pass between the frames of the animated gif.

  If your output format is not `"gif"`, then this parameter does not have any effect.

* `stack`: Selects the PDF rendering stack. Defaults to Ghostscript.

  Use `"pdfium"` for page-specific or single-page high-DPI PDF rasterization when Ghostscript is too slow or exhausts scratch space, for example with high-resolution CAD, blueprint, or layered real-estate PDFs. This stack uses PDFium via the Python `pypdfium2` bindings and Pillow for final image encoding.

  Use `"vips"` only when you explicitly want libvips PDF loading. It is lower-overhead, but PDFium was faster in high-DPI floorplan tests while producing comparable output quality.

  The `"pdfium"` stack currently supports JPG/PNG output, `resize_strategy: "fit"`, a specific `page` or single-page PDFs, opaque hexadecimal backgrounds, `antialiasing`, and `pdf_use_cropbox`.

  The `"vips"` stack currently supports JPG/PNG output, `resize_strategy: "fit"`, a specific `page` or single-page PDFs, and hexadecimal or transparent backgrounds.

* `width`: Width of the new image, in pixels. If not specified, will default to the width of the input image

* `height`: Height of the new image, in pixels. If not specified, will default to the height of the input image

* `resize_strategy`: One of the [available resize strategies](/docs/topics/resize-strategies.md).

* `background`: Either the hexadecimal code or [name](https://www.imagemagick.org/script/color.php#color_names) of the color used to fill the background (only used for the pad resize strategy).

  By default, the background of transparent images is changed to white. For details about how to preserve transparency across all image types, see [this demo](/demos/image-processing/properly-preserve-transparency-across-all-image-types.md).

* `alpha`: Change how the alpha channel of the resulting image should work. Valid values are `"Set"` to enable transparency and `"Remove"` to remove transparency.

  For a list of all valid values please check the ImageMagick documentation [here](http://www.imagemagick.org/script/command-line-options.php#alpha).

* `density`: While in-memory quality and file format depth specifies the color resolution, the density of an image is the spatial (space) resolution of the image. That is the density (in pixels per inch) of an image and defines how far apart (or how big) the individual pixels are. It defines the size of the image in real world terms when displayed on devices or printed.

  You can set this value to a specific `width` or in the format `width`x`height`.

  If your converted image has a low resolution, please try using the density parameter to resolve that.

* `antialiasing`: Controls whether or not antialiasing is used to remove jagged edges from text or images in a document.

* `colorspace`: Sets the image colorspace. For details about the available values, see the [ImageMagick documentation](https://www.imagemagick.org/script/command-line-options.php#colorspace).

  Please note that if you were using `"RGB"`, we recommend using `"sRGB"`. ImageMagick might try to find the most efficient `colorspace` based on the color of an image, and default to e.g. `"Gray"`. To force colors, you might then have to use this parameter.

* `trim_whitespace`: This determines if additional whitespace around the PDF should first be trimmed away before it is converted to an image. If you set this to `true` only the real PDF page contents will be shown in the image.

  If you need to reflect the PDF's dimensions in your image, it is generally a good idea to set this to `false`.

* `pdf_use_cropbox`: Some PDF documents lie about their dimensions. For instance they'll say they are landscape, but when opened in decent Desktop readers, it's really in portrait mode. This can happen if the document has a cropbox defined. When this option is enabled (by default), the cropbox is leading in determining the dimensions of the resulting thumbnails.

* `turbo`: Enables high-performance mode for faster document processing.

  When enabled, Turbo Mode provides two key optimizations:

  1. **Parallel page extraction**: For documents with more than 5 pages, multiple processes run in parallel to extract pages simultaneously. The number of parallel processes scales with the document size (up to 4 processes for documents with 13+ pages).

  2. **Distributed resizing**: Extracted pages are resized concurrently on multiple machines, providing up to 20 times faster processing for large documents.

  Files are emitted as they become available during processing. If you set this to `false`, pages are extracted sequentially using a single process, and files are emitted only after all processing is complete.

  Turbo Mode increases pricing in that the input document's file size is added for every extracted page. There are no performance benefits nor increased charges for single-page documents.
