API

ImageProcessor is the package entry point and the only class. It takes the same config object the JSON config file holds โ€” the file is read into this, nothing more.

import ImageProcessor from "poops-images";

// Minimal โ€” compress images at original size
const processor = new ImageProcessor({
  in: "src/images",
  out: "dist/images",
});
await processor.processAll();
// With sizes and format conversion
const processor = new ImageProcessor({
  in: "src/images",
  out: "dist/images",
  sizes: [
    { name: "thumb", width: 150, height: 150, crop: true },
    { name: "large", width: 1024, height: 0 },
  ],
  format: "webp",
  quality: { jpg: 85, webp: 80 },
  preprocessors: [
    {
      name: "lqip",
      operations: [{ type: "blur", sigma: 30 }],
      sizes: [{ width: 32 }],
      skipOriginal: true,
    },
  ],
});

const stats = await processor.processAll();
// { processed: 12, variants: 48, skipped: 0, bytes: 245760, errors: 0, elapsed: 2300 }

Methods

Call What it does
processAll() Process everything, return the stats object above
processAll({ force: true }) Ignore the cache, regenerate everything
processAll({ dryRun: true }) Log what would be processed, write nothing
watch() Watch the input directory and process incrementally
stopWatch() Stop watching
await processor.processAll({ force: true });
await processor.processAll({ dryRun: true });

processor.watch();
processor.stopWatch();

Note

Validation happens once, in the constructor โ€” a config built in code is checked exactly as one read from disk is, because a library caller never passes through the file loader at all.

See Configuration for every key and Sizes and crops for the size object.