Function cropRegion

  • Apply a mask as the alpha channel of the source image and crop to the mask's bbox, producing a transparent cutout (sprite primitive / CLIP-embed input).

    Parameters

    • source: string | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>
    • mask: SegmentMask
    • opts: {
          pad?: number;
          background?: "transparent" | "opaque";
      } = {}
      • Optional pad?: number

        pixels to expand the crop on each side (default 0)

      • Optional background?: "transparent" | "opaque"

        'transparent' (default) keeps alpha; 'opaque' flattens to black

    Returns Promise<Buffer>