wivo: website image and video optimization
wivo turns source images and videos into web-ready files with fixed, tested presets, and prints the markup for them. Run it instead of writing ffmpeg, sharp or ImageMagick commands yourself. Hand-written commands drift from file to file and from session to session. wivo makes the same file from the same source every time, with the sizes, formats, quality, colour handling and metadata removal already decided.
The command
npx @matterandmotion/[email protected] <command> ...
Always use this exact version: it's what these instructions describe, and a pinned version means every machine makes identical files. Below, wivo stands for that whole command.
| Command | What it does |
|---|---|
wivo check | Confirms wivo can run here (Node, and a test encode with each engine) |
wivo info <files or folders> --json | Size, photo or graphic, transparency; for videos duration, frame rate, codec, HDR, sound |
wivo images <files or folders> --out <folder> [options] --json | Optimizes images |
wivo videos <files or folders> --out <folder> [options] --json | Optimizes videos |
wivo --help lists every option.
Steps
1. Check that wivo runs
Run wivo check once per session, before anything else. If it fails, read references/setup.md. Usually Node is missing or too old, and the user needs to install it. Don't fall back to other tools: the point is identical output.
2. Learn the project
Before choosing settings, find out:
- The framework, from
package.jsonand the config files. It decides between a responsive set with markup and a single master for an image component. references/frameworks.md covers plain HTML, Astro, Next.js, Nuxt, SvelteKit, React with Vite, Gatsby and CMS-backed sites. - Where served files live (
public/,static/, …), and the folders the project already uses for images and videos. Follow the existing convention, e.g.public/imagesandpublic/videos. - Where the originals are. Originals shouldn't be served: they're large and often carry location data. If they sit inside a served folder, suggest a folder that isn't served (e.g.
media/at the project root). Ask before moving the user's files, and never delete them.
3. Look at the files
Run wivo info <files> --json. It tells you each image's size and whether it's a photo or a graphic. For each video it gives the duration, frame rate, sound and HDR. Look at where each file is (or will be) used in the code: the layout decides its role.
4. Choose the settings
Images. --mode:
responsive: several widths and formats, plus<picture>markup to paste in. Use it where the markup is written by hand.master: one high-quality file. Use it where an image component or a CMS makes the sizes (next/image,astro:assets,@nuxt/image, …).
--role sets the widths and the sizes value:
| Role | For |
|---|---|
hero | The large image at the top of a page, often full width. Loads first, with high priority. |
content | Images in the body of a page, up to about 800 px wide. |
card | Thumbnails in grids and lists. |
graphic | Logos, screenshots, diagrams, flat illustrations (lossless). |
auto | The default: graphics become graphic, photos content. |
Videos. --use:
| Use | For | Result |
|---|---|---|
background | Decorative video that loops behind text or in a section | Up to 720p, 30 fps, no sound, autoplaying |
hero | The large video at the top of a page, autoplaying | Up to 1080p, 30 fps, no sound |
content | Video people choose to watch: demos, talks, interviews | Up to 1080p and 60 fps, with sound and controls |
Quality: --quality balanced (the default), unless the user asks for smaller files (lower) or better quality (higher).
Files with the same settings go in one command. If a choice isn't clear from the code or the request, ask the user and say what you'd pick and why. A Hero where a Card was meant gives the wrong widths and loading. references/images.md and references/videos.md have the full presets and the finer decisions.
5. Run it
wivo images media/team.jpg media/office.jpg --out public/images --mode responsive --role content --json
wivo videos media/reel.mov --out public/videos --use background --json
--jsongives you every file, size, warning and the markup to use.--markup jsxfor React files (JSX, TSX); HTML also suits Astro, Svelte and Vue templates.--path: the URL path in the markup is worked out from apublic/orstatic/folder. When the output folder is elsewhere, pass--pathwith the URL it's served at.--dry-runshows the plan without encoding. It's worth showing the user before a long video job or a big batch.
Speed. wivo runs everywhere because its encoders are WebAssembly, but that makes it slower than native tools:
- Images: about 15–30 s each for a large photo, several at once.
- Videos: about 3 s per second of video at 720p, and 5–6 s at 1080p. A 2-minute 1080p video takes around 10 minutes.
Before a long job, tell the user roughly how long it will take. Give it a generous timeout or run it in the background, and don't run two wivo commands at once: each uses every core.
Exit codes: 0 means done. 1 means some files failed and the rest were made (the JSON says which, and why). 2 means a mistake in the command; the message says what to fix.
6. Use the results
- Markup: put each result's
markupwhere the file is used, replacing old references to the original. Search the code for the original file name. - Alt text: describe what a meaningful image shows. Use
alt=""for decorative ones. wivo leavesaltempty, because only you can see what the image is for. widthandheight: keep them. They stop the layout shifting.sizes: wivo's values are starting points. Adjust them when the layout shows how wide the image really is.- Image components: with
master, use the component with the output file and the width and height from the JSON. references/frameworks.md shows how. - Hero videos: put
markup.head(a poster preload) in the page's<head>. - wivo's notes: follow them. An autoplaying video longer than 5 seconds needs a pause button, and a Content video needs captions. references/videos.md has a small pause pattern.
- Commit the outputs and
manifest.json. wivo writesmanifest.jsonin each output folder. Its outputs are reproducible, so to change a file, change the settings and run wivo again on the original. Don't edit outputs, and don't feed them back into wivo. manifest.jsonis public. In a served folder it's published with the site, and it lists the originals' file names. If a name shouldn't be public (a client's internal file name, say), rename the original before running wivo.
7. Report
Tell the user:
- what was made: files, sizes before and after (from the JSON)
- the settings you chose for each file, and why
- any warnings or failures, with wivo's own message
- what's left for them: confirming alt text, writing captions, moving originals, uploading masters to a CMS
When wivo can't do it
wivo doesn't crop, trim, or turn a GIF into a video yet. It can't read HEIC photos or AV1 videos; it tells you to export them as JPEG, or H.264 or HEVC, first. SVGs are already vector: leave them as they are.
Say what's missing and ask the user how to go on. Don't switch to another tool silently: files made a different way are exactly what wivo exists to prevent.
Reference files
- references/setup.md: installing Node on macOS, Windows and Linux, npm and network problems, adding wivo to a project.
- references/images.md: every image preset (widths, formats, quality,
sizes), masters, markup details, placeholders. - references/videos.md: every video preset, sound, long loops, HDR, posters, markup, a pause pattern, captions.
- references/frameworks.md: where files go and how to use the results in each framework, and on CMS-backed sites.