Skip to content
On this page

Home > entanclature > fromFile

fromFile() function

*Process the image from the file path.

Signature:

typescript
export declare function fromFile(path: string, meta: Meta, opts: Opts): Promise<Result>;

Parameters

ParameterTypeDescription
pathstringThe path of the image.
metaMetaThe meta information of the image.
optsOptsThe options for processing.

Returns:

Promise<Result>

The result of the processing.

Remarks

You can't use this function directly. You need to use it through entanclature.

await is required for this function, because we need to calculate the SHA-1 of the file.

Example

typescript
import { entanclature } from "entanclature";

import type { Meta, Opts } from "entanclature";

const filePath = "./path/for/an/image.png";
const meta = [
  { type: "image/png", quality: 80 },
  { type: "image/avif", quality: "+" },
  { type: "image/webp", quality: "-" },
];
const opts: Opts = {
  baseURL: "https://example.com",
  fileDir: "/images/",
};

const result = await entanclature.fromURL(filePath, meta, opts);

console.log(result);

Released under the CC-BY-SA-4.0 License.