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.
Direct usage
Section titled “Direct usage”-
Install
sweetcornandsharp:Terminal window npm i sweetcorn sharpTerminal window pnpm add sweetcorn sharpTerminal window yarn add sweetcorn sharp -
Load an image with
sharp, dither it withsweetcorn, 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.
Framework integrations
Section titled “Framework integrations”Sweetcorn also provides integrations for popular web frameworks: