ChatiumFor developersPlaygroundPricing
Sign in

StorageImageFile

A wrapper class for convenient handling of hash identifiers for image files uploaded to media storage.

Instances of the StorageImageFile class represent runtime values of fields in heap tables declared through Heap.ImageFile and Heap.File (only for image files). It can also be used for easy handling of uploaded image files outside the context of the heap.

Usage/Signature

import { StorageImageFile } from '@app/storage'
const file = new StorageImageFile(hash)

Properties and Methods

All properties of the base class StorageFile (only type always returns image) + ...

getThumbnailUrl(width?: number, height?: number): string

  • Returns the absolute URL of the image thumbnail considering the specified dimensions.

    • If both dimensions are not specified, the original size of the image is used.
    • If one of the dimensions is specified, the other is automatically adjusted according to the original aspect ratio.
    • If both dimensions are specified, the thumbnail is cropped according to the "cover" rule - the image is cropped from both sides either vertically or horizontally depending on the proportions.
  • width: number | undefined
    the width of the required thumbnail in pixels

  • height: number | undefined
    the height of the required thumbnail in pixels

getThumbnailSrc(width?: number, height?: number): { url, width?, height? }

  • Returns an object with the absolute URL and dimensions of the image thumbnail in a format accepted by the src property of the image block, considering the specified dimensions.

  • If both dimensions are not specified, the original size of the image is used.

  • If one of the dimensions is specified, the other is automatically adjusted according to the original aspect ratio.

  • If both dimensions are specified, the thumbnail is cropped according to the "cover" rule - the image is cropped from both sides either vertically or horizontally depending on the proportions.

  • width: number | undefined
    the width of the required thumbnail in pixels

  • height: number | undefined
    the height of the required thumbnail in pixels

width: number
"The strict" width of the image in pixels, determined from the hash property. If for any reason the width cannot be determined, an appropriate exception will be thrown upon access.

widthMaybe: number | undefined
"The non-strict" width of the image in pixels, determined from the hash property. Returns undefined if for any reason the width cannot be determined.

height: number
"The strict" height of the image in pixels, determined from the hash property. If for any reason the height cannot be determined, an appropriate exception will be thrown upon access.

heightMaybe: number | undefined
"The non-strict" height of the image in pixels, determined from the hash property. Returns undefined if for any reason the height cannot be determined.

sizes: { width: number, height: number }
"The strict" dimensions of the image in pixels, determined from the hash property. If for any reason the dimensions cannot be determined, an appropriate exception will be thrown upon access.

sizesMaybe: { width: number, height: number } | undefined
"The non-strict" dimensions of the image in pixels, determined from the hash property. Returns undefined if for any reason the dimensions cannot be determined.