A class representing an Image. This uses operations from Sharp under the hood.

### Hierarchy

- Image

## Index

### Enumerations

- gravity
- kernel
- strategy

### Interfaces

- Color
- CreateOptions
- ExtendOptions
- JpegOptions
- Metadata
- OperationResult
- OverlayOptions
- PngOptions
- ResizeOptions
- WebpOptions

### Constructors

- constructor

### Methods

- background
- crop
- embed
- extend
- flatten
- jpeg
- max
- metadata
- negate
- overlayWith
- png
- resize
- toBuffer
- toImage
- webp
- withMetadata
- withoutEnlargement

## Constructors

### constructor

- new Image(data: ArrayBuffer | CreateOptions): Image

- - Defined in fly/image/index.ts:29

  Constructs a new Image from raw Buffer data

  #### Parameters

  - ##### data: ArrayBuffer | CreateOptions

    Raw image data as a buffer, or options to create a new image

  #### Returns Image

## Methods

### background

- background(rgba: string | Color): this

- - Defined in fly/image/index.ts:154

  Set the background for the `embed`, `flatten` and `extend` operations. The default background is `{r: 0, g: 0, b: 0, alpha: 1}`, black without transparency.

  Delegates to the color module, which can throw an Error but is liberal in what it accepts, clipping values to sensible min/max. The alpha value is a float between `0` (transparent) and `1` (opaque).

  #### Parameters

  - ##### rgba: string | Color

    parsed by the color module to extract values for red, green, blue and alpha.

  #### Returns this

### crop

- crop(crop?: gravity | strategy): this

- - Defined in fly/image/index.ts:120

  Crop the resized image to the exact size specified, the default behaviour.

  Possible attributes of the optional `sharp.gravity` are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`.

  The experimental strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.

  - `entropy`: focus on the region with the highest Shannon entropy.
  - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.

      const cropped = await new Image(input)
        .resize(200, 200)
        .crop(Image.strategy.entropy)
        .toBuffer()

  #### Parameters

  - ##### Optional crop: gravity | strategy

  #### Returns this

### embed

- embed(gravity?: gravity): this

- - Defined in fly/image/index.ts:140

  Preserving aspect ratio, resize the image to the maximum `width` or `height` specified then embed on a background of the exact `width` and `height` specified.

  If the background contains an alpha value then WebP and PNG format output images will contain an alpha channel, even when the input image does not.

      const data = new Image(input)
        .resize(200, 300)
        .background({r: 0, g: 0, b: 0, alpha: 0})
        .embed()
        .toBuffer();

  #### Parameters

  - ##### Optional gravity: gravity

    embed to an edge/corner, defaults to `center`.

  #### Returns this

### extend

- extend(extend: number | ExtendOptions): this

- - Defined in fly/image/index.ts:254

  Pads image by number of pixels. If image is 200px wide, `extend(20)` makes it 220px wide

  #### Parameters

  - ##### extend: number | ExtendOptions

    If numeric, pads all sides of an image.

    Otherwise, pad each side by the specified amount.

  #### Returns this

### flatten

- flatten(flatten: boolean): this

- - Defined in fly/image/index.ts:243

  Merge alpha transparency channel, if any, with `background`.

  #### Parameters

  - ##### flatten: boolean

    Defaults to true

  #### Returns this

### jpeg

- jpeg(options?: JpegOptions): this

- - Defined in fly/image/index.ts:185

  Output image to JPEG

       * // Convert any input to very high quality JPEG output
      const data = await new Image(input)
        .jpeg({
          quality: 100,
          chromaSubsampling: '4:4:4'
        })
        .toBuffer();

  #### Parameters

  - ##### Optional options: JpegOptions

    JPEG output options

  #### Returns this

### max

- max(): this

- - Defined in fly/image/index.ts:89

  Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to the `width` and `height` specified.

  Both `width` and `height` must be provided via `resize` otherwise the behavior will default to `crop`.

      const data = await new ImageinputBuffer)
        .resize(200, 200)
        .max()
        .toBuffer()

  #### Returns this

### metadata

- metadata(): Metadata

- - Defined in fly/image/index.ts:262

  Get metadata from image

  #### Returns Metadata

### negate

- negate(): this

- - Defined in fly/image/index.ts:97

  Produce the "negative" of the image.

  #### Returns this

### overlayWith

- overlayWith(overlay: ArrayBuffer | Image, options?: OverlayOptions): this

- - Defined in fly/image/index.ts:68

  Overlay (composite) an image over the processed (resized, extracted etc.) image.

  The overlay image must be the same size or smaller than the processed image. If both top and left options are provided, they take precedence over gravity.

  If the overlay image contains an alpha channel then composition with premultiplication will occur.

  #### Parameters

  - ##### overlay: ArrayBuffer | Image

    image to overlay

  - ##### Optional options: OverlayOptions

    control how the overlay is composited

  #### Returns this

### png

- png(options?: PngOptions): this

- - Defined in fly/image/index.ts:204

  Use these PNG options for output image.

  PNG output is always full colour at 8 or 16 bits per pixel. Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.

      // Convert any input to PNG output
      const data = await new Image(input)
        .png()
        .toBuffer();

  #### Parameters

  - ##### Optional options: PngOptions

    Compression and encoding options

  #### Returns this

### resize

- resize(width?: number, height?: number, options?: ResizeOptions): this

- - Defined in fly/image/index.ts:54

  Resize image to `width` x `height`. By default, the resized image is center cropped to the exact size specified.

  #### Parameters

  - ##### Optional width: number

    Width in pixels of the resulting image. Pass `undefined` or `null` to auto-scale the width to match the height.

  - ##### Optional height: number

    Height in pixels of the resulting image. Pass `undefind` or `null` to auto-scale the height to match the width.

  - ##### Optional options: ResizeOptions

    Resize options}

  #### Returns this

### toBuffer

- toBuffer(): Promise<OperationResult>

- - Defined in fly/image/index.ts:276

  #### Returns Promise<OperationResult>

### toImage

- toImage(): Promise<Image>

- - Defined in fly/image/index.ts:284

  #### Returns Promise<Image>

### webp

- webp(options?: WebpOptions): this

- - Defined in fly/image/index.ts:220

  Output to webp.

      // Convert any input to lossless WebP output
      const data = await new Image(input)
        .webp({ lossless: true })
        .toBuffer();

  #### Parameters

  - ##### Optional options: WebpOptions

    webp encoding options, quality, etc

  #### Returns this

### withMetadata

- withMetadata(options?: object): this

- - Defined in fly/image/index.ts:234

  Include all metadata (EXIF, XMP, IPTC) from the input image in the output image. The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space. This will also convert to and add a web-friendly sRGB ICC profile.

  #### Parameters

  - ##### Optional options: object

    `options.orientation:` value between 1 and 8, used to update the EXIF `Orientation` tag.

  #### Returns this

### withoutEnlargement

- withoutEnlargement(flag?: boolean): this

- - Defined in fly/image/index.ts:165

  Do not enlarge the output image if the input image width or height are already less than the required dimensions. This is equivalent to GraphicsMagick's `>` geometry option: "change the dimensions of the image only if its width or height exceeds the geometry specification". Use with `max()` to preserve the image's aspect ratio The default behaviour before function call is false, meaning the image will be enlarged.

  #### Parameters

  - ##### Optional flag: boolean

    Toggle option

  #### Returns this

Generated using TypeDoc