image-minimizer
v0.0.8
Published
Image minimizer.
Downloads
452
Maintainers
Readme
image-minimizer
Image minimizer.
Install
yarn add image-minimizer --dev
Usage
import fs from 'node:fs/promises'
import path from 'node:path'
import minifyImages from 'image-minimizer'
const DIRECTORY = new URL('./path/to/directory/', import.meta.url)
let files = await fs.readdir(DIRECTORY, {withFileTypes: true, recursive: true})
files = await Promise.all(
files
.filter((dirent) => dirent.isFile())
.map(async (file) => ({
name: file.name,
content: await fs.readFile(path.join(file.path, file.name)),
})),
)
const compressed = await minifyImages(files)
console.log(compressed)
// -> [<Buffer ...>, ...]
API
minifyImages(fileOrFiles, options?)
options.cache
Type: boolean
Default: true
Enables cache.
options.onFileExtensionError
Type: 'error' | 'warn' | 'ignore' | (file) => void
Default: 'error'
Executes when file extension doesn't match actual file type.