api variations - GetmeUK/hangar51 GitHub Wiki

Variations

Variations allow you to create multiple versions of an image asset by transforming them using a list of image operations.

For an asset to support variations it must be an image, this is determined automatically when a file is uploaded based on the file type, currently the following image formats are supported when uploading assets:

  • bmp
  • gif
  • jpg
  • png
  • tif
  • webp

Variations as specified as a dictionary of named transforms, where each transform provides a list of operations to perform. Each operation in turn is a 2 item list of the form [{op_name}, {op_config}], for example the following transform outputs ensures an image fits within 100 x 100 pixels and is saved out as a webp file at 60% compression:

{
    "thumb": [
        ["fit", [100, 100]].
        ["output", {"format": "webp", "quality": 60}]
        ]
}

Supported operations

The following image operations are currently supported by Hanger51:

["crop", [t, r, b, l]]

Crop the image based on a rectangle given by the top, right, bottom, left coordinates. Coordinates must be a value between 0.0-1.0 (where 1.0 represents the full width/height of the image).

["face", {"bias": [h, v], "padding": p, "min_padding": m}]

Attempt to find a face within the image and crop to it. It's possible to define a bias [horz, vert] and padding to the final crop. The bias and padding must be specified as a percentage of the cropped region.

["fit", [w, h]]

Resize the image to fit with the given width and height (in pixels). The image will only ever be reduced in size if it is smaller than the fit dimensions it will not be scaled up.

["rotate", a]

Rotate the image the given angle where angle is 0, 90, 180, or 270.

["output", {"format": f, "quality": q}]

Set the output format for the image and if supported the quality (where quality is a value between 0-100). The following is a list of supported output image formats and whether they support quality:

  • jpg (supports quality)
  • gif
  • png
  • webp (supports quality)
⚠️ **GitHub.com Fallback** ⚠️