Astro
Install and configure Oxidized Image in an Astro project
Installation
Install the plugin and its peer dependencies using your preferred package manager:
npm install -D @oxidized-image/astro @napi-rs/imageImportant
@napi-rs/image is a required peer dependency and must be installed alongside
@oxidized-image/astro.
Setup
Add the integration to your astro.config.ts:
import { defineConfig } from 'astro/config';
import oxidizedImage from '@oxidized-image/astro';
export default defineConfig({
integrations: [oxidizedImage()],
});This replaces Astro's default Sharp-based image service with the Oxidized Image service, which uses a Rust-based engine via @napi-rs/image for faster encoding.
Configuration
You can customize compression options per format by passing a config object:
import { defineConfig } from 'astro/config';
import oxidizedImage from '@oxidized-image/astro';
export default defineConfig({
integrations: [
oxidizedImage({
jpeg: {
quality: 80,
},
png: {
compressionType: 'best',
},
webp: {
quality: 80,
},
avif: {
quality: 100,
alphaQuality: 100,
speed: 4,
},
}),
],
});Options
| Option | Type | Default | Description |
|---|---|---|---|
jpeg.quality | number | 80 | JPEG quality (1–100) |
png.compressionType | CompressionType | Best | PNG compression level |
png.filterType | FilterType | Adaptive | PNG filter type |
webp.quality | number | 80 | WebP quality (1–100) |
avif.quality | number | 100 | AVIF quality (1–100) |
avif.alphaQuality | number | 100 | AVIF alpha channel quality (1–100) |
avif.speed | number | 4 | AVIF encoding speed (1–10, lower is slower but smaller) |
avif.threads | number | 0 | Number of threads (0 = auto) |