Skip to main content

Compression

The compress plugin uses the Sharp library to compress images into different formats, such as JPEG, PNG, WebP, and AVIF. This helps reduce file sizes while maintaining image quality, ensuring faster load times and better performance. This plugin also supports compressing images using the ASTC, ETC, ETC2, BCn (DXTn) and Basis supercompressed (ETC1S, UASTC) texture compression standard.

Example

Original

Input Image
Input Image
import { compress } from "@assetpack/core/image";

export default {
...
pipes: [
...
// these options are the default values, all options shown here are optional
compress({
jpg: {},
png: { quality: 90 },
webp: { quality: 80, alphaQuality: 80, },
avif: false,
bc7: false,
astc: false,
basis: false,
}),
]
};

API

OptionTypeDescription
jpgobject | falseAny settings supported by sharp jpeg.
pngobject | falseAny settings supported by sharp png.
webpobject | falseAny settings supported by sharp webp.
avifobject | falseAny settings supported by sharp avif.
Defaults to false.
bc7object | falseAny settings supported by bc7.
Defaults to false.
astcobject | falseAny settings supported by astc.
Defaults to false.
basisobject | falseAny settings supported by basis.
Defaults to false.

Tags

TagFolder/FileDescription
ncbothIf present the image(s) will not be compressed.

Example

Original

Input Image
Input Image