Media / foldkit-media

Reading an image's facts

An ImageAsset's facts are derived from its original once, where it enters, and stored beside it. describe lives in the core package; each inspector lives in the subpath for its runtime (/sharp, /browser, /cloudflare), and factsOf lives in foldkit-media/server:

  • describe(key, bytes) reads them through the Inspector: size, alpha, the SHA-256 hash, and a ThumbHash when the inspector generates thumbnails.
  • inspectorSharp({ maxPixels? }) (Node) reads all of them; alpha is true only when a pixel is transparent, so opaque PNGs still receive placeholders.
  • inspectorBrowser({ maxPixels? }) (foldkit-media/browser) reads them in the browser or a web worker, with its own decoder: an editor describes a dropped file (including ThumbHash and hash) before upload and stores its facts beside the image (such as a rich-text Image's asset). Unrecognized formats fail decoding.
  • inspectorImages(binding) (Cloudflare) reads the size from info without billing a transformation. It skips thumbnails and marks non-JPEG images as having alpha so placeholders remain accurate.
  • factsOf(url, { allow, maxBytes?, cache?, fetch? }) describes an image named only by URL (such as a rich-text image), giving it dimensions like any other. It accepts only https URLs on exact hosts in allow at the default port, re-checking redirects and bounding streamed bytes. Given a KeyValueStore as cache, facts are cached by URL and revalidated with ETag.