zimg
v0.1.0
Published
Pre-optimize images for Next.js production or others via sharp
Downloads
60
Readme
zimg
Pre-optimize images for Next.js production or others via sharp
Installation
$ npm install zimg
CLI Usage
Use npx:
$ npx zimg <cwd> [options]
Globally install:
$ npm install zimg -g
$ zimg --help
zimg/0.1.0
Usage:
$ zimg [cwd]
Commands:
[cwd] Optimize images for production via sharp
For more info, run any command with the `--help` flag:
$ zimg --help
Options:
-p, --pattern <pattern> Glob pattern to match files, default to `**/*.{jpg,jpeg,png}`
-s, --sizes <sizes> Sizes to generate, default to `[640, 720, 1280, 1600]`
-q, --quality <quality> Quality of generated images, default to `75`
-v, --version Display version number
-h, --help Display this message
API Usage
import { zimg } from 'zimg'
await zimg({
cwd: process.cwd(),
pattern: '**/*.{jpg,jpeg,png}',
sizes: [640, 720, 1280, 1600],
quality: 75
})
// searching images in cwd, and resize it
API Reference
zimg(options?)
options
cwd
- Type:
string
- Details: Current working directory
- Default:
process.cwd()
pattern
- Type:
string
- Details: Glob pattern to match files
- Default:
'**/*.{jpg,jpeg,png}'
filename
- Type:
string
- Details: Filename of optimized image
- Default:
'[name].[size]'
sizes
- Type:
number[]
- Details: Sizes to generate
- Default:
[640, 720, 1280, 1600]
quality
- Type:
number
- Details: Quality of generated images
- Default:
75
skipOptimized
- Type:
boolean
- Details: Skip optimized images rather than overwrite
- Default:
true
Related
- zce/velite - Turns Markdown / MDX, YAML, JSON, or others into app's data layer with Zod schema.
- zce/caz - A simple yet powerful template-based Scaffolding tools.
Contributing
- Fork it on GitHub!
- Clone the fork to your own machine.
- Checkout your feature branch:
git checkout -b my-awesome-feature
- Commit your changes to your own branch:
git commit -am 'Add some feature'
- Push your work back up to your fork:
git push -u origin my-awesome-feature
- Submit a Pull Request so that we can review your changes.
NOTE: Be sure to merge the latest from "upstream" before making a pull request!