ChatiumFor developersPlaygroundPricing
Sign in

getThumbnailUrl

Creates a link to an image of the desired size based on the file hash. What is a file hash and where to find it

function getThumbnailUrl(
  ctx: app.Ctx, // context
  hash: string, // file hash,
  width?: number, // width
  height?: number, // height
) : string

Accepts parameters ctx, hash, width, and height. For width and height, you can pass both parameters or just one. If both parameters are provided, the image will be resized on the server side according to the principle of object-fit: contain. If only one parameter is provided, the other will be calculated automatically while maintaining the aspect ratio of the image. Parameters:

  • width - width of the image in pixels
  • height - height of the image in pixels

Returns: URL for the thumbnail image

Example

import {getThumbnailUrl} from '@app/storage'
import {jsx} from '@app/html-jsx'

app.html('/', () => {
  const hash = 'image_aB3kHmKgLn.7301x4873.jpeg'
  return <html><body>
    <p>
      Width and height parameters are set:
      <img src={getThumbnailUrl(hash, 100, 100)} />
    </p>
    <p>
      Width parameter is set, height is omitted:
      <img src={getThumbnailUrl(hash, 100, undefined)} />
    </p>
    <p>
      Height parameter is set, width is omitted:
      <img src={getThumbnailUrl(hash, undefined, 100)} />
    </p>
  </body></html>
})