Documentation
Source Images
Creating Tiled TIFFs

Alpha Channels

⚠️

Some versions of libvips and libjpeg have an issue with JPEG-compressed pyramidal TIFF images that include more than 3 channels (e.g., alpha channels). If you find that serverless-iiif returns an error for an image request or isn't rendering as you'd expect, try removing any additional channels beyond red, green, and blue. The conversion commands below should ensure that your images are flattened with the alpha channel removed.

Using the VIPS command line

# For a 3-channel source image
vips tiffsave "source_image.tif" output_image.tif --tile --pyramid --compression jpeg --tile-width 256 --tile-height 256
 
# For a source image with an alpha channel
vips extract_band "source_image.tif" temp_image.v 0 --n 3 \
  && vips tiffsave temp_image.v output_image.tif --tile --pyramid --compression jpeg --tile-width 256 --tile-height 256 \
  && rm temp_image.v

Using ImageMagick

convert source_image.tif \
  -alpha off \
  -define ptif:pyramid=256x4 \
  -define tiff:tile-geometry=256x256 \
  -define tiff:generate-pyramids=true \
  -compress jpeg \
  'ptif:output_image.tif'

Using GraphicsMagick

gm convert source_image.tif \
  -flatten \
  -define tiff:tile-geometry=256x256 \
  -compress jpeg \
  'ptif:output_image.tif'

Using the Included Create Tiled TIFF Script

The serverless-iiif source repository includes a script that can convert a source image stored in an AWS S3 bucket to a tiled, multi-resolution TIFF and write it to another AWS S3 bucket.

Specs

The script makes several assumptions, which may or may not be what you want, but its settings should work well for most use cases.

  • Flattens the image to three channels, removing the alpha channel if present
  • Reduces the image to a maxiumum of 15,000 pixels per side
  • Rotates the image to EXIF Orientation 1 (opens in a new tab)
  • Creates the pyramidal TIFF using JPEG compression at 75% quality, with a tile size of 256x256 pixels

Prerequisites

Step 1

Make sure the AWS CLI is properly configured (opens in a new tab) with credentials that have read access to the source S3 bucket and read/write access to the destination S3 bucket.

Step 2

Clone this repository.

Step 3

Install runtime dependencies:

npm ci

Step 4

Run the script:

npm run create-tiled-tiff s3://source-bucket/path/to/source/image s3://destination-bucket/path/to/output/image.tif

Step 5

Verify the output:

aws s3api head-object --bucket destination-bucket --key path/to/output/image.tif