Options
All
  • Public
  • Public/Protected
  • All
Menu

A helper class to provide common functionality for working with Image objects

Hierarchy

  • ImageHelper

Index

Constructors

Methods

  • createThumbnail(src: any, options: { width: number; height: number; tx: number; ty: number; center: boolean; format: string; quality: number }): Promise<any>
  • Create thumbnail preview for a provided image path.

    Parameters

    • src: any

      The URL or display object of the texture to render to a thumbnail

    • options: { width: number; height: number; tx: number; ty: number; center: boolean; format: string; quality: number }

      Additional named options passed to the compositeCanvasTexture function

      • width: number
      • height: number
      • tx: number
      • ty: number
      • center: boolean
      • format: string
      • quality: number

    Returns Promise<any>

    The parsed and converted thumbnail data

  • hasImageExtension(src: string): boolean
  • Test whether a source file has a supported image extension type

    Parameters

    • src: string

      A requested image source path

    Returns boolean

    Does the filename end with a valid image extension?

  • compositeCanvasTexture(object: DisplayObject, [options]?: { width: number; height: number; tx: number; ty: number; center: boolean }): Texture
  • Composite a canvas object by rendering it to a single texture

    Parameters

    • object: DisplayObject

      The object to render to a texture

    • [options]: { width: number; height: number; tx: number; ty: number; center: boolean } = {}

      Options which configure the resulting texture

      • width: number
      • height: number
      • tx: number
      • ty: number
      • center: boolean

    Returns Texture

    The composite Texture object

  • textureToImage(texture: Texture, options?: { format: string; quality: number }): Promise<string>
  • Extract a texture to a base64 PNG string

    Parameters

    • texture: Texture

      The texture object to extract

    • options: { format: string; quality: number } = {}
      • format: string
      • quality: number

    Returns Promise<string>

    A base64 png string of the texture

  • pixiToBase64(target: DisplayObject, type: string, quality: number): Promise<string>
  • Asynchronously convert a DisplayObject container to base64 using Canvas#toBlob and FileReader

    Parameters

    • target: DisplayObject

      A PIXI display object to convert

    • type: string

      The requested mime type of the output, default is image/png

    • quality: number

      A number between 0 and 1 for image quality if image/jpeg or image/webp

    Returns Promise<string>

    A processed base64 string

  • canvasToBase64(canvas: HTMLCanvasElement, type: string, quality: number): Promise<string>
  • Asynchronously convert a canvas element to base64.

    Parameters

    • canvas: HTMLCanvasElement
    • type: string
    • quality: number

    Returns Promise<string>

    The base64 string of the canvas.

  • uploadBase64(base64: string, fileName: string, filePath: string, [options]?: { storage: string; type: string; notify: boolean }): Promise<any>
  • Upload a base64 image string to a persisted data storage location

    Parameters

    • base64: string

      The base64 string

    • fileName: string

      The file name to upload

    • filePath: string

      The file path where the file should be uploaded

    • [options]: { storage: string; type: string; notify: boolean } = {}

      Additional options which affect uploading

      • storage: string
      • type: string
      • notify: boolean

    Returns Promise<any>

    A promise which resolves to the FilePicker upload response

  • pixelsToCanvas(pixels: Uint8ClampedArray, width: number, height: number, options?: { element: HTMLCanvasElement; ew: number; eh: number }): HTMLCanvasElement
  • Create a canvas element containing the pixel data.

    Parameters

    • pixels: Uint8ClampedArray

      Buffer used to create the image data.

    • width: number

      Buffered image width.

    • height: number

      Buffered image height.

    • options: { element: HTMLCanvasElement; ew: number; eh: number } = {}
      • element: HTMLCanvasElement
      • ew: number
      • eh: number

    Returns HTMLCanvasElement