Skip to content

Getting started

Sweetcorn is a collection of JavaScript packages that dither images using Sharp. You can use it directly to process images, or via a framework integration.

  1. Install sweetcorn and sharp:

    Terminal window
    npm i sweetcorn sharp
  2. Load an image with sharp, dither it with sweetcorn, and save the result:

    import sharp from 'sharp';
    import sweetcorn from 'sweetcorn';
    const inputImage = await sharp('input.png');
    const ditheredImage = await sweetcorn(inputImage, {
    algorithm: 'floyd-steinberg',
    });
    ditheredImage.webp({ lossless: true }).toFile('output.webp');

Read more in the “Usage in Node.js” guide.

Sweetcorn also provides integrations for popular web frameworks: