Skip to content

Generate TypeScript typings, preferably automagically #472

Description

@davidreher

first of all thx for your amazing library. I am writing an application using sharp. I would like to use TypeScript but unfortunately your library doesn't come with typings included.

I already started implementing some of them and would like to know if its worth the work to complete them so you can include them into your package. You could also think about generating the docs from the type definitions.

declare module "sharp" {
  function s(input: string | Buffer, options?: any): s.ISharpImage;

  namespace s {
    interface ISharpImage {
      /**
       * Fast access to image metadata without decoding any compressed image data.
       */
      metadata(cb?: (error?: Error, metadata?: IMetadata) => void): void;
      /**
       * Takes a "snapshot" of the instance, returning a new instance. Cloned instances inherit the input of their parent instance.
       * 
       * This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
       */
      clone(): ISharpImage;
      resize(width?: number, height?: number, options?: any): ISharpImage;
      max(width?: number, height?: number): ISharpImage;
      min(width?: number, height?: number): ISharpImage;
      rotate(angle?: number): ISharpImage;
      toFile(path: string, callback?: (err?: Error, info?: any) => void): any;
    }

    /**
     * image metadata
     */
    interface IMetadata {
      /**
       * Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
       */
      format: 'jpeg' | 'png' | 'webp' | 'gif' | 'svg';
      /**
       * Number of pixels wide
       */
      width: number;
      /**
       * Number of pixels high
       */
      height: number;
      /**
       * Name of colour space interpretation e.g. srgb, rgb, scrgb, cmyk, lab, xyz, b-w ...
       */
      space: string;
      /**
       * Number of bands e.g. `3` for sRGB, `4` for CMYK
       */
      channels: number;
      /**
       * Boolean indicating the presence of an embedded ICC profile
       */
      hasProfile: boolean;
      /**
       * Boolean indicating the presence of an alpha transparency channel
       */
      hasAlpha: boolean;
      /**
       * Number value of the EXIF Orientation header, if present
       */
      orientation: number;
      /**
       * Buffer containing raw EXIF data, if present
       */
      exif: Buffer;
      /**
       * Buffer containing raw ICC profile data, if present
       */
      icc: Buffer;
    }
  }

  export = s;
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions